我有一个 UITableView,它从代表标题、摘要和目标 URL 的字符串数组中获取数据。当用户选择一个单元格时,应用程序会转到包含 WebView 的 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
委托(delegate)方法(正如原始问题评论中也指出的那样)。
关于ios - prepareForSegue :sender: gets wrong sender,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20860955/