-2

I have a custom UITableViewController with many UITableViewCells inside, each of which has a checkbox. Within the custom UITableViewCell class there is a method which happens when the checkbox is checked. I also have an NSMutableArray as a property of the UITableViewController and I want to add an object to it everytime the checkbox is checked but I am having trouble accessing the other class. Some help please?

5
  • after lots of searching & writing logic for this problem, i found the perfect solution on apple developer demo for TableViewCell Accessory for it. try it. Commented Jun 8, 2014 at 19:10
  • @pawan - You shouldn't have to search that hard, since this question is asked about once a day, and the solution is trivial. Commented Jun 8, 2014 at 20:21
  • @HotLicks i did not search for this question, i was telling my experience , when i had started my career as ios app developer. its about 3 years ago , i found this solution. Commented Jun 8, 2014 at 20:23
  • @pawan - Yeah, and the question's been asked once a day for about 4 years, that I know of. Commented Jun 8, 2014 at 20:25
  • @HotLicks absolutely correct. thats why i posted it as comment not answer. i think this question should be closed with duplicate flag. Commented Jun 8, 2014 at 20:26

1 Answer 1

2

If you have custom cell class, create a cell's delegate.

@class MyCustomTableViewCell;

@protocol MyCustomCellDelegate <NSObject>
- (void)cell:(MyCustomTableViewCell *)cell checkboxValueDidChange:(BOOL)checked;
@end

@interface MyCustomTableViewCell : UITableViewCell
@property(nonatomic, weak) id <MyCustomCellDelegate> delegate;
@end

Then in tableView:cellForRowAtIndexPath: assign your controller as table view cell's delegate. Having this, you'll receive callback.

- (void)cell:(MyCustomTableViewCell *)cell checkboxValueDidChange:(BOOL)checked {
    // get cell's index path if you need
    if (checked) {
        [self.myMutableArray insertObject:myObject atIndex:myIndex];
    }
}

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.