zoukankan      html  css  js  c++  java
  • ios-创建根视图控制器的三种方式

    1、纯代码创建根视图控制器,在Appdelegate中的didFinishLaunchingWithOptions
    self.window =[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
        //设置窗口根窗口控制器
        self.window.rootViewController
        //将窗口作为主窗口被设置可见
        [self.window makeKeyWindow];
    2、通过storyboard文件来创建,加载storyboard中的控制器就可以了。从这个文件中实例化控制器。当你自己创建了个storyboard可以这样进行设置,但是你要保证你的这个storyboard文件不为空,以及设置了Is Initial View Controller.如果我们是用系统自带的就不要去修改了还是直接用就可以了。

    self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
        //加载文件
        UIStoryboard * board=[UIStoryboard storyboardWithName:@"ZXStoryboard" bundle:nil];//nil就代表在mainBundle这个路径下
        //从storyboard中实例化控制器
        UIViewController * viewController=[board instantiateInitialViewController];
        self.window.rootViewController=viewController;
        [self.window makeKeyAndVisible];
    3、xib创建控制器,先创建自定义控制器类,然后指定xib文件,修改xib文件中的File's Owner的custom class,设置为你自定义的控制器类,
    self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    XibViewController * xibVc=[[XibViewController alloc]initWithNibName:@"ZXib" bundle:nil];
    self.window.rootViewController=xibVc;
    [self.window makeKeyAndVisible];

    作者:清风_____
    链接:https://www.jianshu.com/p/52197559b7c7
    来源:简书
    著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
  • 相关阅读:
    域名解析成功但ping不通解决方案
    PHP如何通过rabbitMQ死信队列实现业务的延时/定时操作
    短视频自导自演,分镜脚本如何设计
    如何在uni-app中使用fingerprint2实现游客设备标识
    以PHP门面模式实现简单的邮件发送
    搜索接口优化方案——幂集分词表
    CUMTCTF'2020 未完成 wp
    CUMTCTF'2020 已做wp
    Sqli-labs 1-10
    ETCD组件在grpc中的实践
  • 原文地址:https://www.cnblogs.com/Im-Victor/p/13212852.html
Copyright © 2011-2022 走看看