ios - indexpath 行未准备好 segue 以进行详细信息披露

标签 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 附件按钮:执行模式转场(编辑)
+ Button (Navigation bar button Item): 执行模态转场(Add)

最佳答案

如果您在 Storyboard中连接了辅助操作,则 prepareForSegue:sender: 中的 sender 将是被点击的单元格。这意味着你可以做类似的事情

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

关于ios - indexpath 行未准备好 segue 以进行详细信息披露,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14813786/

相关文章:

ios - 如何在突出显示时使图像变暗(在 Collection View 中)?

ios - NSUserDefaults 是持久的吗?

iphone - UIButton.layer.cornerRadius 不存在?

objective-c - Swift 中的强引用和弱引用

iphone - 如何从表中删除所有行?

iphone - 为什么这个方向代码不起作用?

iOS - UIView subview 的大小与 super View 不同

android - 如何在 iOS 上注册 React Native 模块

javascript - 使用 JavaScript 在 iPhone 的虚拟键盘中捕获 "done"按钮单击

ios - 'JSQSystemSoundPlayer' 错误没有可见的@interface