【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
图片说明

全部评论

相关推荐

07-15 16:52
已编辑
门头沟学院 Java
周五投的,流程今天结束
投递地平线等公司7个岗位
点赞 评论 收藏
分享
点赞 评论 收藏
分享
程序员小白条:这比例牛逼,750:1
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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