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.Pawan Rai– Pawan Rai2014-06-08 19:10:40 +00:00Commented 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.Hot Licks– Hot Licks2014-06-08 20:21:37 +00:00Commented 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.Pawan Rai– Pawan Rai2014-06-08 20:23:29 +00:00Commented 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.Hot Licks– Hot Licks2014-06-08 20:25:04 +00:00Commented 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.Pawan Rai– Pawan Rai2014-06-08 20:26:52 +00:00Commented Jun 8, 2014 at 20:26
Add a comment
|
1 Answer
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.