Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement