Skip to content

Instantly share code, notes, and snippets.

@shrijitsingh99
Created February 7, 2016 12:52
Show Gist options
  • Save shrijitsingh99/4814dc63c25fa25022c3 to your computer and use it in GitHub Desktop.
Save shrijitsingh99/4814dc63c25fa25022c3 to your computer and use it in GitHub Desktop.
@interface TableViewController ()
@end
@implementation TableViewController
- (id)initWithStyle:(UITableViewStyle)style {
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.array = [[NSMutableArray alloc] init];
for (NSMutableDictionary *objectData in [Object getObjects]) {
Object *object = [[Object alloc] initWithData:objectData andImage:nil];
[self.array addObject:object];
}
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if ([self.array count] == 0) {
return 0;
}
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
return [self.array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:@"Cell"
forIndexPath:indexPath];
Object *object = self.array[indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:@"%d", (int)indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView
accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
[self.tableView beginUpdates];
[self.array removeObjectAtIndex:[indexPath row]];
if ([self.tableView numberOfRowsInSection:indexPath.section] == 1) {
[self.tableView
deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section]
withRowAnimation:UITableViewRowAnimationAutomatic];
} else {
[self.tableView deleteRowsAtIndexPaths:@[ indexPath ]
withRowAnimation:UITableViewRowAnimationAutomatic];
}
[self.tableView endUpdates];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment