iOS中storyboard的问题

浏览:77日期:2023-11-17

问题描述

storyboard中设置了两个界面。

在代码中使用

[self.navigationController pushViewController:[[SCMainViewController alloc]init] animated:YES];

怎么跳转过去没有加载啊

不能再用纯代码方式去跳转了吗。。只能用segue吗

问题解答

回答1:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@'xxx' bundle:nil]; SCMainViewController *vc = [storyboard instantiateViewControllerWithIdentifier:NSStringFromClass([SCMainViewController class])]; [self.navigationController pushViewController:vc animated:YES];回答2:

可以跳转的,感觉你的 Stroyboard 上相对应的 ViewController 没有关联 Class - SCMainViewController。

回答3:

id loadViewControllerFromStoryboard(NSString *name,NSString *identifier){ UIStoryboard *storyboard = [UIStoryboard storyboardWithName:name bundle:nil]; UIViewController *vc = nil;if (identifier == nil) {vc = [storyboard instantiateInitialViewController]; } else {vc = [storyboard instantiateViewControllerWithIdentifier:identifier]; }if ([vc isKindOfClass:[UIViewController class]]) {return vc; } return nil;}回答4:

先要在storyBoard里面填好StoryBoard IDiOS中storyboard的问题

然后使用下面的代码加载viewController:

UIViewController *listController = [[UIStoryboard storyboardWithName:@'Main' bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@'listViewController'];回答5:

1.绑定类iOS中storyboard的问题

2.push

相关文章: