3 回答
TA贡献1810条经验 获得超5个赞
在故事板中,转到“属性”检查器并设置视图控制器的标识符。然后,您可以使用以下代码显示该视图控制器。
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"myViewController"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
TA贡献1856条经验 获得超11个赞
斯威夫特3
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "viewController")
self.navigationController!.pushViewController(vc, animated: true)
斯威夫特2
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("viewController")
self.navigationController!.pushViewController(vc, animated: true)
条件
将故事板ID分配给视图控制器。
故事板ID
IB>显示身份检查器>身份>故事板ID
斯威夫特(遗产)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("viewController") as? UIViewController
self.navigationController!.pushViewController(vc!, animated: true)
编辑:Swift 2在Fred A.的评论中提出
如果你想在没有任何navigationController的情况下使用你必须使用如下:
let Storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = Storyboard.instantiateViewController(withIdentifier: "viewController")
present(vc , animated: true , completion: nil)
TA贡献1853条经验 获得超18个赞
在属性检查器中,为该视图控制器提供标识符,以下代码适用于我
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
DetailViewController *detailViewController = [storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
[self.navigationController pushViewController:detailViewController animated:YES];
- 3 回答
- 0 关注
- 506 浏览
添加回答
举报