Ios 如何获取传递给performsguewithidentifier的数据
回答这个问题可能需要两秒钟,但我的搜索技能并没有让我在这个问题上走得很远。我正在执行一个segue,但我不确定如何获取目标上的id。这是我在tableview控制器上的代码Ios 如何获取传递给performsguewithidentifier的数据,ios,objective-c,cocoa-touch,segue,Ios,Objective C,Cocoa Touch,Segue,回答这个问题可能需要两秒钟,但我的搜索技能并没有让我在这个问题上走得很远。我正在执行一个segue,但我不确定如何获取目标上的id。这是我在tableview控制器上的代码 - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath: NSIndexPath *)indexPath{ NSLog(@"reaching accessoryButtonTappedForRowWithI
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath: NSIndexPath *)indexPath{
NSLog(@"reaching accessoryButtonTappedForRowWithIndexPath:");
[self performSegueWithIdentifier:@"leads_calls_to_detail" sender:[[self.leads_calls objectAtIndex:indexPath.row] objectForKey:@"ID"]];
}
我必须在目标视图控制器上创建什么才能获取我试图传递的id,或者我执行序列的方式是否与我正在尝试的不兼容?您应该将值传递给
destinationViewController
内部prepareForSegue:
并将self
作为发送方传递。。尝试使用以下方法:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([[segue identifier] isEqualToString:@"leads_calls_to_detail"])
{
YourViewController *controller=(YourViewController *)segue.destinationViewController;
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
//Or rather just save the indexPath in a property in your currentViewController when you get the accessoryButtonTappedForRowAtIndexPath callback, and use it here
controller.yourPropertyToSet = [self.leads_calls objectAtIndex:path.row];
}
}
根据Rob Mayoff的说法,您可以通过如下方式获取附件所在行的索引路径:
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];//where sender is the sender passed in from prepareForSegue:
您需要实现一个,在其中您可以参考segue.destinationController。谢谢!我想我可以从这里找到答案!:)