1、Cell中的l.h文件中添加代理方法
@class settingCell;
@protocol settingCellDelegate <NSObject>
-(void)updateSwitchAtCell:(settingCell *)cell mySwitch:(UISwitch *)mySwitch;
@end
@property (weak,nonatomic)id<settingCellDelegate>delegate;
3、viewController中实现cell的代理方法
-(void)updateSwitchAtCell:(settingCell *)cell mySwitch:(UISwitch *)mySwitch
{
NSIndexPath *index=[self.tableView indexPathForCell:cell];
switch (index.row) {
case 1:
break;
case 2:
break;
case 3:
break;
default:
break;
}
NSLog(@"%ld",index.row);
NSLog(@"--%d",mySwitch.on);
}
- (IBAction)switchDidClick:(UISwitch *)sender {
if ([self.delegate respondsToSelector:@selector(updateSwitchAtCell:mySwitch:)]) {
[self.delegate updateSwitchAtCell:self mySwitch:sender];
}
}