【发布时间】:2012-11-21 07:37:29
【问题描述】:
我有一个简单的UITableView,只有一个部分和几行。当用户单击单元格附件按钮(与detailsSegue 连接时。我想知道它是哪个单元格行。所以我可以从我的数组中选择正确的对象并将其分配给下一个视图中的变量。
我使用了委托方法 tableview:accessoryButtonTappedForRowWithIndexPath: 并将 indexPath 值分配给我的私有属性 myRow。比在prepareForSegue:sender: 方法中,我使用我的self.myRow.row 值从数组中选择正确的对象。
我的问题是这两种方法似乎以错误的顺序执行。从 NSLog 我可以看到 prepareForSegue:sender: 方法首先执行,我的委托方法在它之后更改了 self.myRow 的值。
所以prepareForSegue:sender: 方法总是将错误的对象传递给下一个视图(之前点击的那个)。
对不起我的英语伙计们。提前感谢您的帮助。
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {
self.myRow = indexPath;
NSLog(@"tapped button at row: %i",self.myRow.row);
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([segue.identifier isEqualToString:@"addSegue"]) {
AddViewController *avc = segue.destinationViewController;
avc.delegate = self;
}
else if ([segue.identifier isEqualToString:@"detailsSegue"]) {
NSLog(@"Segue row: %i",self.myRow.row);
Annotation *annotation = [self.viewsList objectAtIndex:self.myRow.row];
NSLog(@"Segue annotation object: %@",annotation.title);
DetailsViewController *dvc = segue.destinationViewController;
dvc.wikiKey = annotation.title;
}
}
【问题讨论】:
标签: objective-c ios uitableview segue