gpt4 book ai didi

indexing - 获取 UITableView 中选定附件按钮的 IndexPath

转载 作者:行者123 更新时间:2023-12-02 22:16:56 26 4
gpt4 key购买 nike

我的 UItableViewCell 附件按钮有问题。我的附件按钮通过 segue“连接”到另一个 UIViewController。当我点击附件按钮时,我从模型中获取对象,并将该对象“传递”到 segue destinationViewController。这是我准备segue方法:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"IdentityCard"])
{
NSLog(@"%i" ,self.tableView.indexPathForSelectedRow.row);
[segue.destinationViewController showIdentityCardForTeacher:[self.teachers getTeacherInPosition:self.tableView.indexPathForSelectedRow.row]];
}
}

问题是方法开头(“if”之后)的 NSLog 始终显示数字 0!我尝试实现该方法:

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

但是prepare for segue方法是在此方法之前执行的,所以我无法设置任何@property来“保存”indexPath。我该如何解决这个问题?

最佳答案

在:

-(void)prepareForSegue:(UIStoryboardSegue *)segue 发件人:(id)sender

...您有“sender”参数,可让您知道已被点击的配件的单元格,因此:

index = [self.tableView indexPathForCell:sender].row;

您可以获取它的索引以便使用它。

那么你就不需要使用tableView的accessoryButtonTappedForRowWithIndexPath方法了。

关于indexing - 获取 UITableView 中选定附件按钮的 IndexPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13517414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com