我是Objective-C的新手。我有一個表格視圖和一個網址列表。當用戶點擊表格視圖中的單元格時,它們將被引導至具有顯示網站的網頁視圖的第二個視圖控制器。但是,當我運行該應用程序時,Web視圖顯示爲空白。我認爲didSelectRowAtIndexPath是問題。那麼如何將URL傳遞給第二個視圖控制器?didSelectRowAtIndexPath不傳遞url到下一個視圖控制器?
ListTableViewController.m
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
FeaturedWebViewController *vc = [[FeaturedWebViewController alloc] init];
vc.url = cell.textLabel.text;
[self.navigationController pushViewController:vc animated:YES];
}
FeaturedWebViewController.m
NSURL *URL = [NSURL URLWithString: [self.url stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
[self.webView loadRequest:request];
我會仔細檢查cell.textLabel.text是否具有正確的值;也許在代碼中停下來,並確保vc.url包含你期望的字符串。如果看起來不錯,那麼問題可能在FeaturedWebViewController中。也許從String到NSURL的轉換失敗了?不確定...如果您仍然遇到問題,請發佈代碼。 –
我們還需要在使用'.url'值的地方看到第二個視圖控制器的代碼。 – Putz1103
我不會從單元拉取數據,從您填充單元格的結構中獲取數據。 –