欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

iOS storyboard 与 xib 间相互跳转

程序员文章站 2024-03-24 10:03:52
...

项目结构

iOS storyboard 与 xib 间相互跳转

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 文件,如下图操作

iOS storyboard 与 xib 间相互跳转