Tuesday, December 30, 2014

Blocks in UITableViewCell


@interface MyTableViewCell

@property(nonatomic, copy) void (^checkboxHandler)(void);

@end


@implementation MyTableViewCell

- (IBAction)checkboxPressed:(UIButton *)sender {
self.checkboxHandler();
}

@end



@implementation MyTableViewController

- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyTableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"cell"
    forIndexPath:indexPath;
    cell.checkboxHandler = ^{
    // Perform the desired work in response to checkbox
    };
    return cell;
}

@end


No comments: