Select UITableView's row when clicking on UISwitch

后端 未结 7 836
眼角桃花
眼角桃花 2020-12-06 07:45

I have a UITableView with UISwitchs on them.

\"TableView\"

When the switch is

7条回答
  •  伪装坚强ぢ
    2020-12-06 08:46

    I had to do double mySwitch.superview.superview to get the proper cell.

    Here's an example

    - (void)switchToggle:(UISwitch *)mySwitch
    {
    
     UITableViewCell *cell = (UITableViewCell *)mySwitch.superview.superview;
     NSIndexPath *indexpath = [self.tableView indexPathForCell:cell];
     NSLog(@"toggle section %d rowID %d", indexpath.section, indexpath.row);
    
    }
    

提交回复
热议问题