[英]prepareForSegue and PerformSegueWithIdentifier sender
[英]prepareForSegue:sender: gets wrong sender
我有一个UITableView,它从代表标题,摘要和目标URL的字符串数组中获取数据。 当用户选择一个单元格时,该应用程序会选择包含Web视图的View Controller。
问题是无论选择哪个单元格,传递的数据始终是第一个单元格...
( self.mockData
是我正在使用的虚拟硬连线数组,直到开始处理模型为止)
下面的代码,非常感谢任何帮助。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"destinationWebView" sender:[self tableView:self.tableView cellForRowAtIndexPath:indexPath]];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"destinationWebView"]) {
MyCustomWebPageViewController *destinationViewController = [segue destinationViewController];
if ([destinationViewController canPerformAction:@selector(setArticleUrl:) withSender:self]) {
if (self.urlOut) {
self.urlOut = nil;
}
NSIndexPath *indexPath = [self.tableView indexPathForCell:sender];
NSString *urlString = [[self.mockData objectAtIndex:indexPath.row] objectAtIndex:2];
self.urlOut = [NSURL URLWithString:urlString];
[destinationViewController setArticleUrl:self.urlOut];
}
}
}
我认为将以下内容替换为performSegueWithIdentifier
行:
[self performSegueWithIdentifier:@"destinationWebView" sender:[self.tableView cellForRowAtIndexPath:indexPath]];
这与您现在向UITableView
询问单元格(而不是UITableViewDataSource
委托方法)相同(在原始问题注释中也已指出)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.