iphone - 用于从accessoryButton 继续的索引路径

标签 iphone storyboard

我正在尝试使用 Storyboard/segue 来处理具有标准转换和详细信息披露按钮的 UITableView 之间的转换。在这里阅读了一些不同的帖子后,我已经这样设置了我的项目:

  1. 在 UITableViewCell 和 ViewController 之间绑定(bind) main segue
  2. 将辅助 Segue 从父 ViewController 绑定(bind)到新 ViewController
  3. 实现 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/

相关文章:

iphone - 为 iOS Xcode 创建和实现数据库

ios - 在肖像中,它工作正常,但在风景中,它出现在半屏上,我正在使用 wAny hAny 尺寸类别

iphone - 核心位置第一点无效

ios - 将 presentModalViewController 与 Storyboard一起使用

iphone - 如何使用uiwebview显示一些网页?

ios - Xcode 4.2 iOS 空应用程序和 Storyboard

ios - 使用 CATransition 的自定义 Segue 不工作

iOS:可以导出/导入 Storyboard布局

ios - 一个 View 中的多个 TableView

iphone - 为 UIImage 制作圆角