2012-12-21 57 views
9

推的viewController我有這樣的代碼iOS的 - 從代碼和故事板

PlaceViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"PlaceView"]; 
[self presentViewController:newView animated:YES completion:nil]; 

而且我可以改變看法,但我將推動這一觀點時,我在此頁面返回的狀態持續。

我嘗試把這個代碼:

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

,但不會做任何事情。

感謝

回答

3

對於故事板,你應該使用performSegueWithIdentifier像這樣:

[self performSegueWithIdentifier:@"identifier goes here" sender:self]; 
+0

在哪裏? (對不起,不知道) – Xose

+0

而不是'[self.navigationController pushViewController:newView animated:YES];'你應該使用'[self performSegueWithIdentifer:@「You identifier」sender:self];' – Sumanth

+0

「沒有可見的@interface聲明選擇「performSegueWithIdentifer:發件人」」 我有這樣的錯誤 – Xose

36
PlaceViewController *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"storyBoardIdentifier"]; 
[self.navigationController pushViewController:newView animated:YES]; 

檢查兩件事情,

  1. 你的故事板標識符是正確的。

  2. 根視圖具有導航控制器。

+0

喜不得到導航 –

+0

@JigneshB:你與導航控制器連接?檢查第二點,2.根視圖有導航控制器。 –

0

默認情況下,Xcode創建一個標準的視圖控制器。我們首先將視圖控制器更改爲導航控制器。選擇菜單中的簡單選擇「編輯器」並選擇「嵌入」,然後選擇「導航控制器」 第1步。選擇Main story board 第2步。點擊Xcode應用程序頂部的「Editor」。 第3步:點擊「嵌入」

Xcode中會自動嵌入與導航控制器的視圖控制器。

1

斯威夫特3.X

let viewController = storyboard?.instantiateViewController(withIdentifier: "storyboardIdentifier") as! UIViewController 
navigationController?.pushViewController(viewController, animated: true) 
0

用途:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"STORYBOARD_NAME" bundle:nil]; 
PlaceViewController *newView = [storyboard instantiateViewControllerWithIdentifier:@"PlaceView"]; 
[self presentViewController:newView animated:YES completion:nil]; 

或者:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"STORYBOARD_NAME" bundle:nil]; 
PlaceViewController *newView = [storyboard instantiateViewControllerWithIdentifier:@"PlaceView"]; 
[self.navigationController pushViewController:newView animated:YES];