我有一个 tableView,我想通过单击单元格中心的按钮切换到另一个视图。我使用动态单元格。
所以,我想通过单击单元格中的按钮切换到视图(在导航控制器中),我该如何在 prepareForSegue 中做到这一点?我可以获取单元格的索引,然后通过单击公开来执行此步骤,但是当我单击位于单元格中心的按钮时,索引路径不存在。这里的代码:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
UIViewController *destination = segue.destinationViewController;
if ([destination respondsToSelector:@selector(setDelegate:)]) {
[destination setValue:self forKey:@"delegate"];
}
if ([destination respondsToSelector:@selector(setSelection:)]) {
NSIndexPath *indexPath = [self.tableFeed indexPathForCell:sender];
NSString *idUser = [self.arrIDUser objectAtIndex:indexPath.row];
NSLog(@"%@",idUser);
NSString *pattern = [self.arrPattern objectAtIndex:indexPath.row];
NSMutableDictionary *selection = [[NSMutableDictionary alloc] initWithObjectsAndKeys:idUser,@"idUser", pattern, @"pattern", nil];
[destination setValue:selection forKey:@"selection"];
}
}