簡體   English   中英

prepareForSegue: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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM