【iOS学步】Xcode删除Main.StoryBoard,使用纯代码相关操作

iOS开发中,如果想使用纯代码方式设置窗口初始状态,可以删掉Main.StoryBoard,需要在AppDelegate中使用代码,并在Info.plist配置文件中将一些键值对删除,否则处理不当会出现崩溃或者黑屏。
相关操作如下:
1.在AppDelegate.h中声明一个UIWindow属性,在AppDelegate.m中实例化:

//AppDelegate.h
@property (nonatomic, strong) UIWindow *myWindow;

//AppDelegate.m
    CGRect frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
    self.myWindow = [[UIWindow alloc] initWithFrame:frame];
    [self.myWindow makeKeyAndVisible];
    self.myWindow.backgroundColor = [UIColor whiteColor];

    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[ViewController alloc] init]];

    self.myWindow.rootViewController = nav;

这里以UINavigationController作为UIWindow的根控制器为例。

2.Info.plist配置文件中删掉两个键值对:Application Scene Manifest和Main storyboard file base name
图片说明

全部评论

相关推荐

11-19 18:44
已编辑
成都理工大学 Java
程序员花海:我面试过100+校招生,大厂后端面试不看ACM,竞赛经历含金量低于你有几份大厂实习 这个简历整体来看不错 可以海投
如何写一份好简历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务