簡體   English   中英

iOS 7:如何從其他方法更改為另一個UIViewController?

[英]iOS 7: How to change to another UIViewController from an others method?

我有兩個UIViewController,在故事板中都有各自的視圖。 在其中之一中,我有一個被調用的函數,並且我希望它可以更改為其他ViewControllers視圖。 我嘗試了這個:

BRLoggedViewController *obj = [[BRLoggedViewController alloc] initWithNibName:@"BRLoggedViewController" bundle:nil];

[self.navigationController pushViewController:obj animated:NO];

我記錄了第一個,它被調用了(我的意思是構造函數),但是視圖沒有改變。 我忘記了什么? 感謝您的幫助

如果使用情節提要,則必須從情節提要中獲取視圖,如下所示:

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

確保ViewController在InterfaceBuilder中為您的Storyboard設置了正確的Storyboard標識符。

你為什么不使用segues? 在情節提要中,繪制您的序列,然后在代碼中觸發該序列

[self performSegueWithIdentifier:@"YourSegueNameAsItIsInStoryboard" sender:self];

如果需要,管理您的

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM