Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @interface MyTVC : UIViewController
- @property (strong, nonatomic) NSMapTable switchesToIndexPaths;
- @end
- @implementation MyTVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Initialise the map table
- self.switchesToIndexPaths = [NSMapTable weakToStrongObjectsMapTable];
- ....
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- // Create the cell as usual
- // Map the switch of the cell with the indexpath
- [self.switchesToIndexPaths setObject:indexPath forKey:cell.switch];
- [cell.switch addTarget:self @selector:(switchValueChanged:) forControlEvents:UIControlEventValueChanged];
- // Do the other stuff and return the cell
- }
- - (void)switchValueChanged:(UISwitch *)switch {
- // Get the indexpath from the switch
- NSIndexPath *indexPath = [self.switchesToIndexPaths objectForKey:switch];
- if (indexPath != nil) {
- // You will now know exactly which row and section this switch was for
- }
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement