[英]iOS how to segue a selected cell value into another view controller
我有一个已成功用字典数组填充的Uitableview单元格。 现在,我很难将选定的单元格值传递给另一个视图控制器并显示该值。
这是我的代码:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"Tapped: %@",[[feeds objectAtIndex:indexPath.row]objectForKey:@"IncidentNumber"]);
someProperty = [[feeds objectAtIndex:indexPath.row]objectForKey:@"IncidentNumber"];
[self performSegueWithIdentifier:@"item" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if ([[segue identifier] isEqualToString:@"yourSegue"])
{
DescriptionViewController *vc;
vc = segue.destinationViewController;
vc.item_pass = someProperty;
}
}
您使用标识符项执行segue,但稍后在prepareForSegue
,检查标识符为yourSegue的segue ...
代替实现didSelectRowAtIndexPath
将segue连接到表视图单元格(而不是视图控制器)。
然后,将所选单元格作为sender
参数传递给prepareForSegue
,您可以使用以下命令获取索引路径
let selectedIndexPath = tableView.indexPathForCell(sender as! UITableViewCell)!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.