Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. @interface TableViewController ()
  2.  
  3. @end
  4.  
  5. @implementation TableViewController
  6.  
  7. - (id)initWithStyle:(UITableViewStyle)style {
  8. self = [super initWithStyle:style];
  9. if (self) {
  10. // Custom initialization
  11. }
  12. return self;
  13. }
  14.  
  15. - (void)viewDidLoad {
  16. [super viewDidLoad];
  17.  
  18. self.array = [[NSMutableArray alloc] init];
  19.  
  20. for (NSMutableDictionary *objectData in [Object getObjects]) {
  21. Object *object = [[Object alloc] initWithData:objectData andImage:nil];
  22.  
  23. [self.array addObject:object];
  24. }
  25. }
  26.  
  27. #pragma mark - Table view data source
  28.  
  29. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  30. if ([self.array count] == 0) {
  31. return 0;
  32. }
  33. return 1;
  34. }
  35.  
  36. - (NSInteger)tableView:(UITableView *)tableView
  37. numberOfRowsInSection:(NSInteger)section {
  38. // Return the number of rows in the section.
  39. return [self.array count];
  40. }
  41.  
  42. - (UITableViewCell *)tableView:(UITableView *)tableView
  43. cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  44. UITableViewCell *cell =
  45. [tableView dequeueReusableCellWithIdentifier:@"Cell"
  46. forIndexPath:indexPath];
  47.  
  48. Object *object = self.array[indexPath.row];
  49. cell.textLabel.text = [NSString stringWithFormat:@"%d", (int)indexPath.row];
  50.  
  51. return cell;
  52. }
  53.  
  54. - (void)tableView:(UITableView *)tableView
  55. accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
  56. [self.tableView beginUpdates];
  57. [self.array removeObjectAtIndex:[indexPath row]];
  58. if ([self.tableView numberOfRowsInSection:indexPath.section] == 1) {
  59. [self.tableView
  60. deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]
  61. withRowAnimation:UITableViewRowAnimationAutomatic];
  62. } else {
  63. [self.tableView deleteRowsAtIndexPaths:@[ indexPath ]
  64. withRowAnimation:UITableViewRowAnimationAutomatic];
  65. }
  66. [self.tableView endUpdates];
  67. }
  68.  
  69. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement