[英]iOS how to segue a selected cell value into another view controller
I have a Uitableview cell that has been successfully populated with dictionary array. 我有一个已成功用字典数组填充的Uitableview单元格。 Right now, i have difficulty passing the selected cell value to another view controller and display that value.
现在,我很难将选定的单元格值传递给另一个视图控制器并显示该值。
Here is my codes: 这是我的代码:
- (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 ...
Instead of implementing didSelectRowAtIndexPath
connect the segue to the table view cell (rather than to the view controller). 代替实现
didSelectRowAtIndexPath
将segue连接到表视图单元格(而不是视图控制器)。
Then the selected cell is passed as sender
parameter in prepareForSegue
and you can get the index path with 然后,将所选单元格作为
sender
参数传递给prepareForSegue
,您可以使用以下命令获取索引路径
let selectedIndexPath = tableView.indexPathForCell(sender as! UITableViewCell)!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.