iOS storyboard 与 xib 间相互跳转
程序员文章站
2024-03-24 10:03:52
...
项目结构
storyboard 跳转到 xib
restaurantViewController *vc = [[restaurantViewController alloc] initWithNibName:@"restaurantViewController" bundle:[NSBundle mainBundle]];
[self presentViewController:vc animated:YES completion:^{
NSLog(@"进入");
}];
xib 跳转到 storyboard
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
ViewController *vc = [sb instantiateViewControllerWithIdentifier:@"main"];
[self presentViewController:vc animated:YES completion:^{
NSLog(@"退回");
}];
注意:
[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]]; 代码中的Main是 storyboard 文件的名字。
ViewController *vc = [sb instantiateViewControllerWithIdentifier:@"main"]; 代码中main是 Storyboard ID,如何设置呢,点击要跳转的 storyboard 文件,如下图操作
上一篇: UI绘制流程详解(2)
下一篇: 字节跳动-面试 二分法解决 第K大的数字