来自accessoryButton的segue的IndexPath [英] IndexPath for segue from accessoryButton

查看:135
本文介绍了来自accessoryButton的segue的IndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用storyboard / segue来处理UITableView与标准转换以及详细信息披露按钮之间的转换。在这里阅读了几个不同的帖子后,我以这种方式设置了我的项目:

I am attempting to use a storyboard/segue to handle the transition between a UITableView with both standard transition as well as detail disclosure button. Having read a few different posts on here I have set up my project this way:


  1. UITableViewCell和ViewController之间的主要区域

  2. 将辅助segue从父ViewController绑定到新的ViewController

  3. 实现 accessoryButtonTappedForRowWithIndexPath ,如下所示:

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
    [self performSegueWithIdentifier:@"DetailSegue" sender:self];
}


这很有效,我的 prepareForSegue:sender:按预期调用。麻烦的是,我需要知道所选元素的indexPath。来自UITableViewCell的segue检索indexPath,如下所示:

This works great and my prepareForSegue: sender: gets called as expected. The trouble is, I need to know the indexPath for the element selected. The segue from the UITableViewCell retrieves the indexPath like this:

NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

不幸的是,当我尝试调用accessoryButton时,返回 null

Unfortunately when I try to do that having called the accessoryButton, that returns null.

我基于这段代码的原始问题是:详细信息披露按钮和分段

The original question I am basing some of this code off of is here: Detail Disclosure Button and Segues

是否有tableView的方法返回indexPath for accessoryButtons?我是否需要以其他方式访问indexPath?

Is there a method of the tableView which returns indexPath for accessoryButtons? Do I need to access the indexPath in some other manner?

推荐答案

您不必覆盖 accessoryButtonTappedForRowWithIndexPath

prepareForSegue 中,使用详细信息披露按钮时,而不是:

In prepareForSegue, when working with a detail disclosure button, instead of:

[self.tableView indexPathForSelectedRow]

使用:

[self.tableView indexPathForCell:sender]

发件人已经是详细信息披露按钮的单元格。

The sender is already the detail disclosure button's cell.

这篇关于来自accessoryButton的segue的IndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆