【发布时间】:2013-09-30 18:37:03
【问题描述】:
我以编程方式创建了一个 UITableView 并将 UISwitch 添加到它的单元格附件视图中。
这是我在cellForRowAtIndexPath 方法中的单元格附件视图中的 UISwitch 代码。
UISwitch *accessorySwitch = [[UISwitch alloc]initWithFrame:CGRectZero];
[accessorySwitch setOn:NO animated:YES];
[accessorySwitch addTarget:self action:@selector(changeSwitch:) forControlEvents:UIControlEventValueChanged];
cell.accessoryView = accessorySwitch;
这是点击按钮后调用的方法。
- (void)changeSwitch:(UISwitch *)sender{
UITableViewCell *cell = (UITableViewCell *)[sender superview];
NSIndexPath *indexPath = [self.filterTableView indexPathForCell:cell];
NSLog(@"%ld",(long)indexPath);
……………. My other code…….
}
我能够在 iOS 6 中打印索引路径值 但在 iOS 7 中它打印 nil,
我是在 iOS 7 中遗漏了什么,还是有其他方法可以在 iOS 7 中获取 indexPath
谢谢, 阿伦。
【问题讨论】:
标签: iphone ios uitableview ios7