2015-04-02 91 views
0

我有一個UITableViewController動態行,對於每一行,我需要打開一個新的viewcontroller。 我試過使用performSegueWithIdentifier,但它不起作用,因爲我沒有故事板標識符。performSegueWithIdentifier without storyboard idendentifier

如何動態打開新的viewcontroller

我已經試過:

newUiViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:@"controller"]; 
[self.navigationController pushViewController:controller animated:YES]; 

,但它不工作。

+0

有在故事板稱爲「控制器」一個UIViewController有用嗎? – Ilario 2015-04-02 12:31:47

+2

當它不起作用時會發生什麼?任何錯誤消息或堆棧跟蹤?你有沒有檢查'控制器'是否爲零? – clearlight 2015-04-02 12:32:40

+0

錯誤消息是:「原因:'故事板()不包含標識符爲'controller'的視圖控制器」 – user3576455 2015-04-02 12:44:25

回答

1

你應該在你的故事板給控制器標識,檢查:

enter image description here

類是你的「newUiViewController」和故事板ID「菜單中的」就是你的「控制器」

那麼你就可以做:

newUiViewController *controller = (newUiViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"controller"]; 
[self.navigationController pushViewController:controller animated:YES]; 
+0

完成,但現在我沒有任何異常,沒有任何反應 – user3576455 2015-04-02 13:16:06

+0

可能我需要更改appdelegate文件。如何改變它? – user3576455 2015-04-02 13:32:35

0

好吧,我找到了解決方案。 像navcontroller我使用「SWRevealViewController」,所以正確的代碼是:

UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController; 
[navController setViewControllers: @[list] animated: YES]; 

[self.revealViewController setFrontViewController:navController]; 
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES]; 

我認爲這是對其他