zoukankan      html  css  js  c++  java
  • iOS开发手记

    我原先是这么做的,通常也是这么做

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        ViewController *firstVC = [[ViewController alloc] init];
        UINavigationController *naviController = [[UINavigationController alloc] initWithRootViewController:firstVC];
        self.window.rootViewController = naviController;
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        return YES;
    }
     
    

     然而运行后,UINavigationController的确作为windows的根视图显示了,但是firstVC里的控件却没有显示,一片空白

    事实证明不能这样直接alloc firstVC,而是要从storyboard中加载,我改成如下就行了:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
        // Override point for customization after application launch.
        UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_" bundle:nil];
        ViewController *firstVC = [storyBoard instantiateViewControllerWithIdentifier:@"MainView"];
        UINavigationController *naviController = [[UINavigationController alloc] initWithRootViewController:firstVC];
        self.window.rootViewController = naviController;
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        return YES;
    }
    

    我查看过很多代码例子都是像前者一样直接alloc加载就可以,但是我这里却不行,一定要这样从storyboard中加载,我哪里没注意到望大神告知

  • 相关阅读:
    1210 BBS admin后台管理及侧边栏筛选个人站点
    1209 BBS 登录
    更换 npm 源国内镜像 cnpm
    Linux软件管理
    apt-get / yum 软件安装源(国内)
    修改pip源为国内镜像源(加速下载)
    修改浏览器搜索引擎:网址应该如何填写
    如何根据实际问题选择一个合适的数学模型
    安装向量和矩阵运算库函数
    配置编译器(GCC和GFortran)
  • 原文地址:https://www.cnblogs.com/dcai/p/5738851.html
Copyright © 2011-2022 走看看