相关疑难解决方法(0)

IOS 7 - 如何从放置在UITableViewCell中的按钮获取indexPath

我以编程方式创建了一个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;
Run Code Online (Sandbox Code Playgroud)

这是单击按钮后调用的方法.

- (void)changeSwitch:(UISwitch *)sender{

    UITableViewCell *cell = (UITableViewCell *)[sender superview];

    NSIndexPath *indexPath = [self.filterTableView indexPathForCell:cell];
    NSLog(@"%ld",(long)indexPath);

 ……………. My other code…….
}
Run Code Online (Sandbox Code Playgroud)

我能够在iOS 6中打印索引路径值但是在iOS 7中它打印为nil,

我在iOS 7中遗漏了什么,或者在iOS 7中有其他方法来获取indexPath

谢谢,阿伦.

iphone uitableview ios ios7

29
推荐指数
3
解决办法
3万
查看次数

标签 统计

ios ×1

ios7 ×1

iphone ×1

uitableview ×1