我有我的代碼中的單獨控制器故事板中的多個視圖。從另一個控制器加載視圖
廠景 - ViewController1
視圖2 - ViewController2
VIEW3 - ViewController3
我想從ViewController2調用VIEW3。
loadAnotherView { 的NSLog(@ 「loadAnotherView」);
//代碼載入另一個視圖
}
請告知。謝謝。
我有我的代碼中的單獨控制器故事板中的多個視圖。從另一個控制器加載視圖
廠景 - ViewController1
視圖2 - ViewController2
VIEW3 - ViewController3
我想從ViewController2調用VIEW3。
loadAnotherView { 的NSLog(@ 「loadAnotherView」);
//代碼載入另一個視圖
}
請告知。謝謝。
如果你真的要做到這一點,把一個參考ViewController3
爲ViewController2
,然後調用它的view
方法。但是,這並不是一件好事,因爲視圖控制器應該管理自己的視圖,而不是從另一個控制器加載視圖。
試試這些代碼行,也許他們幫助你。
UIStoryboard *storyboard = self.storyboard;
ViewControllerName *vc = [storyboard instantiateViewControllerWithIdentifier:@"Menu"];
[self presentViewController: vc animated:YES completion:nil];
通常有一個特定的方法,您可以使用故事板時可以使用,它可以幫助您切換到另一個視圖控制器。它應該比第一行代碼更舒服:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([segue.identifier isEqualToString:@"Start"]) {
MenuTableViewController *mtvc = [segue destinationViewController];
}
}