2017-06-06 40 views
0

我需要使用UITableViewController創建文件瀏覽器功能。iOS實現文件瀏覽器推送相同的視圖控制器顯示錯誤

我加載數據中的tableview,如果在索引路徑用戶選擇的行是一個文件夾,

欲推相同的數據結構和的UITableView並使用重載的tableview以改變保存視圖中的數據顯示控制器。

所以我儘量在didSelectRowAtIndexPath方法委託方法添加

[self.navigationController pushViewController:self animated:YES]; 

所有方法代碼:

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

    [self.navigationController pushViewController:self animated:YES]; 
} 

但我得到的錯誤日誌低於

Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: 'Pushing the same view controller instance more than once is not supported 

我使用pushViewController因爲iOS的可以顯示回預覽文件的標題和具有導航動畫。

有沒有人可以教我如何解決問題或有一些更好的功能實現方法?

非常感謝。

+0

爲什麼你想再次推相同的viewController?爲什麼你只是沒有改變tableView的dataSource? 你可以實現你自己的後退按鈕什麼會改變dataSource後,用戶按下它 –

+0

,因爲我改變了數據源和重新加載,它不能顯示視圖控制器之間的視圖控制器的動畫。所以我認爲推一個新的視圖控制器。 – dickfala

回答

0

它可能的解決方法 - 這是分配新的實例類,並將其推入navigationController,而不是推self

類似的東西:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    YourController *controller = [[YourController alloc] init] 
    [self.navigationController pushViewController: controller animated:YES]; 
} 
+0

我嘗試使用你的提示,除非導航欄會顯示黑屏。 – dickfala

+0

okey,我嘗試其他方法,使用mainStoryboard instantiateViewControllerWithIdentifier:@「myVC」];然後推動VC,它可以推動相同的視圖控制器。 – dickfala

0

您可以使用此方法:

[self.navigationController pushViewController: [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"YourViewController"] animated: YES]; 
相關問題