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

全部评论

相关推荐

01-12 17:45
门头沟学院 Java
985废物一枚:就是问问你能不能接受北京的房租,hr也知道公司工资不高,大概率是要贴钱的
找实习记录
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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