2015-10-04 15 views
0

我有一些代碼用於啓動在故事板中創建的模式視圖控制器,並帶有故事板ID。對於新的情況,我試圖調整它以呈現ViewController,它實際上是主導航系統中表格的詳細視圖。我試圖在應用程序中跳轉,如果可能的話。IOS/objective-c/xcode:在代碼中實例化DetailView控制器

在這種情況下,VC不應該是模態的。相反,我想讓用戶訪問表的普通細節視圖。

爲了使它更具挑戰性,我需要詳細視圖來獲取對象數據。幸運的是,這應該在初始VC中出現。

這是我啓動模態VC的代碼。

UIStoryboard *storyBoard = self.storyboard; 
     detailVC *newVC = 
     [storyBoard instantiateViewControllerWithIdentifier:@"detailView"]; 
     //pass object to new VC 
     detailVC.object = _object;//pass data object 
     UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: dareVC]; 
     [self presentModalViewController:nav animated:YES]; 

編輯:以下代碼也推出非模態VC。但是,初始細節視圖不含數據。數據被保存,所以如果我回來了,數據在那裏,但最初,我得到沒有數據的通用屏幕。

detailVC *secondViewController = 
     [self.storyboard instantiateViewControllerWithIdentifier:@"detail"]; 
     [self.navigationController pushViewController:secondViewController animated:YES]; 
     secondViewController.object=_object; 

回答

0
detailVC *secondViewController = 
     [self.storyboard instantiateViewControllerWithIdentifier:@"detail"]; 
     secondViewController.object=_object; 
     [self.navigationController pushViewController:secondViewController animated:YES]; 

首先實例化。 然後設置數據。 然後按下它。

相關問題