2016-07-16 92 views
0

首先,請提前致謝! 其次,我搜索和檢查論壇的答案是有幫助的,但找不到任何有幫助的東西。我知道這是一個很重要的領域。如何將表格視圖中的信息傳遞到詳細視圖

所以我試圖從表視圖推送信息到詳細信息視圖控制器。信息在plist上。我用來獲取此代碼的教程很舊,並使用xibs。用故事板,它會引發以下錯誤:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 

我知道這是因爲我沒有名爲「DetailViewController」一個XIB文件。我希望這個(以及來自plist的信息)被推送到我的故事板中的「DetailViewController」,但是我找不到執行此操作所需的代碼。

你能幫我解決嗎?我需要做些什麼改變?

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

NSString *BibleVerses = [BibleReading objectAtIndex:indexPath.row]; 
if (!self.detailViewController) { 
    self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil]; 
} 
self.detailViewController.detailItem = BibleVerses; 
[self.navigationController pushViewController:self.detailViewController animated:YES]; 
} 
+0

爲什麼要使用一個額外的筆尖,由於您使用的故事板呢?爲什麼不使用segue這是最簡單的代碼最簡單的方法。 – vadian

回答

0

如果您的控制器在故事板中,則可以使用instantiateViewControllerWithIdentifier方法。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

NSString *BibleVerses = [BibleReading objectAtIndex:indexPath.row]; 
if (!self.detailViewController) { 
    self.detailViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"]; 
} 
self.detailViewController.detailItem = BibleVerses; 
[self.navigationController pushViewController:self.detailViewController animated:YES]; 
} 
+0

輝煌,工作完美!非常感謝! 當定時器允許我選擇作爲答案! –

0

使用此代碼,

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSString *BibleVerses = [BibleReading objectAtIndex:indexPath.row]; 
    UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    self.detailViewController = [storyboard instantiateViewControllerWithIdentifier:@"YourViewControllerIdentifierName"]; 

    self.detailViewController.detailItem = BibleVerses; 
    [self.navigationController pushViewController:self.detailViewController animated:YES]; 
} 

希望它有幫助

相關問題