【问题标题】:Load View Controller via code通过代码加载视图控制器
【发布时间】:2012-03-06 17:18:47
【问题描述】:
我的故事板有几个 ViewController,通过按钮相互连接。
现在我需要在特定条件为真时加载另一个 UIViewController。我设法创建了一个新的子类,但我想避免它。我只是想要
if(condition == true){
// load viewcontroller located in the storyboard, not connected with anything else
}
有什么帮助吗?
【问题讨论】:
标签:
objective-c
xcode
view
controller
viewcontroller
【解决方案1】:
好的,我会详细说明:
使用应该使用UIStoryBoard类的- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier方法,但一定要在IB中填写你的控制器的标识符字段。
UIStoryboard *storybrd = [UIStoryboard storyboardWithName:@"YourStoryBrdName" bundle:nil];
UIViewController *mycontroller =[storybrd instantiateViewControllerWithIdentifier:@"myIdent"];
现在您应该拥有您的控制器并按照您的喜好展示它。