indexpath行没有准备细节披露的segue

时间:2013-02-11 14:13:43

标签: ios objective-c

 if([segue.identifier isEqualToString:@"Edit"]){

    AddCoffeeViewController *avc = [segue destinationViewController];

    Coffee *coffeeObj = [appDelegate.coffeeArray objectAtIndex:arow];
    NSLog(@"ViewController.m prepareForSegue: arow: %d coffeeName:%@ price:%@      coffeeID:%d",arow,coffeeObj.coffeeName,coffeeObj.price,coffeeObj.coffeeID);
    [coffeeObj setIsInEditMode:YES];
    avc.EditCoffeeObj = coffeeObj;


}

当我按下附件按钮时,我没有得到正确的行。

虽然在下面的方法我得到正确的行。 如果我不想使用任何ivar,我有什么方法可以为segue准备正确的行。

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{

arow = indexPath.row;

}

enter image description here


tableViewCell附件按钮:执行模态segue(编辑)
+按钮(导航栏按钮项目):执行模态segue(添加)

3 个答案:

答案 0 :(得分:34)

如果您在故事板中附加了附件操作,那么sender中的prepareForSegue:sender:将是被点按的单元格。这意味着您可以执行类似

的操作
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];

答案 1 :(得分:3)

附件按钮轻敲和选中的行是两个不同的东西。在accessoryButtonTappedForRowWithIndexPath中,只需将indexPath设置为全局变量,然后在segue中使用它。

答案 2 :(得分:0)

SWIFT 3.0 解决方案;与Objective-C版本非常相似。所以Cell是发件人,我们通过单元接收 indexPath ,其中附件被按下

<div itemprop="name" class="sc_team_member_name">
  <a href="link_to_person" rel="bookmark"> </a>                           
</div>