`
lizhuang
  • 浏览: 887183 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

storyboard UIViewController init

 
阅读更多
Assuming you have storyboard, go to storyboard and give your VC an identifier (inspector), then do:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"IDENTIFIER"]; [self.navigationController pushViewController:vc animated:YES];

Assuming you have a xib file you want to do:

UIViewController *vc = [[UIViewController alloc] initWithNibName:@"NIBNAME" bundle:nil]; [self.navigationController pushViewController:vc animated:YES];
Without a xib file:

UIViewController *vc = [[UIViewController alloc] init]; [self.navigationController pushViewController:vc animated:YES];

从xib中加载UIview
 
NSArray *niblets = [[NSBundle mainBundle] loadNibNamed:@"sample" owner:self options:NULL];
for (id theObject in niblets)
    {
        if ([theObject isKindOfClass:[UIViewController class]])
            [self.navigationController pushViewController:theObject animated:YES];
    }
或者[niblets objectindex:0]
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics