我正在尝试使用 Storyboard/segue 来处理具有标准转换和详细信息披露按钮的 UITableView 之间的转换。在这里阅读了一些不同的帖子后,我已经这样设置了我的项目:
- 在 UITableViewCell 和 ViewController 之间绑定(bind) main segue
- 将辅助 Segue 从父 ViewController 绑定(bind)到新 ViewController
实现
accessoryButtonTappedForRowWithIndexPath
如下:-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { [self performSegueWithIdentifier:@"DetailSegue" sender:self]; }
这效果很好,我的 prepareForSegue: sender:
按预期被调用。问题是,我需要知道所选元素的索引路径。 UITableViewCell 的 segue 检索索引路径,如下所示:
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
不幸的是,当我尝试调用accessoryButton 时,它返回null
。
我基于这些代码的原始问题在这里:Detail Disclosure Button and Segues
tableView 是否有一个方法可以返回accessoryButtons 的indexPath?我需要以其他方式访问indexPath吗?
最佳答案
您不必覆盖accessoryButtonTappedForRowWithIndexPath
。
在 prepareForSegue
中,使用详细信息披露按钮时,而不是:
[self.tableView indexPathForSelectedRow]
用途:
[self.tableView indexPathForCell:sender]
发件人已经是详细信息披露按钮的单元格。
关于iphone - 用于从accessoryButton 继续的索引路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9339302/