2013-02-11 51 views
16
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; 


} 

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

虽然在下面的方法,我得到正确的行。 有没有什么办法,我可以得到正确的行准备继续,如果我不想使用任何伊娃。indexpath行没有进入准备细节的详细披露

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

arow = indexPath.row; 

} 

enter image description here


tableViewCell附件按钮:执行模式赛格瑞(编辑)
+按钮(导航栏按钮项):执行模式赛格瑞(添加)

+0

为什么不只是地方直接赛格瑞里面accessoryButtonTappedForRowWithIndexPath准备? – 2013-02-11 14:18:18

+0

我想通过咖啡类对象。如果使用[self performSegueWithIdentifier:@“Edit”sender:nil];那么有没有我可以通过Coffee类对象。 – 2013-02-11 14:27:10

+0

注意:从附件按钮调用segue最早是在iOS6中引入的。一个很好的解决方法是创建一个自定义单元格并添加一个按钮并从该按钮调用segue。 – Groot 2013-02-11 14:48:55

回答

34

如果您已将迷你配件动作连接到故事板中,那么prepareForSegue:sender:中的sender将是被点击的单元格。这意味着你可以做这样的事情

NSIndexPath *indexPath = [self.tableView indexPathForCell:sender]; 
+0

嘿你的解决方案是正确的。谢谢很多。我不明白为什么有些人会对我的问题给予负面的评价。只是尝试一下,你会面临同样的问题。 – 2013-02-11 14:41:00

+0

爱你的家伙。非常感谢 – 2013-11-20 12:46:54

+0

感谢很多家伙。 – shaikh 2013-12-04 09:44:51

3

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

0

SWIFT 3.0解决方案;与Objective-C版本非常相似。因此,细胞是发送者和我们收到indexPath通过细胞在附件压

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if let destination = segue.destination as? YourViewController { 
     let indexPath = tableView.indexPath(for: sender as! UITableViewCell)! 
    } 
} 
相关问题