【问题标题】:iPhone - App always starts with an empty white screen?iPhone - 应用程序总是以空白屏幕开始?
【发布时间】:2013-09-09 03:22:56
【问题描述】:

我的 iPhone 应用无法在启动时显示任何内容。 知道这里有什么问题吗?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
     HomeViewController *t = [[HomeViewController alloc] init];
     [self.window addSubview:t.view];
     [self.window makeKeyAndVisible];

     // I tried the following in case the problem is my
     //view controller but nothing shows up at all
     UISegmentedControl *t = [[UISegmentedControl alloc] init];
     [self.window addSubview:t];
     [self.window makeKeyAndVisible];
}

【问题讨论】:

    标签: iphone uiviewcontroller uisegmentedcontrol


    【解决方案1】:

    除非您的视图控制器实现loadView,否则您应该从带有initWithNibName:bundle: 的NIB 文件加载视图。

    应使用initWithItems: 初始化分段控件。您还应该为控件分配一个框架。

    【讨论】:

    • 实际上这是我的问题,我在我的笔尖名称“HomeViewController.m.xib”中留下了“.m”,我正确地重命名了它并解决了问题
    • 如果 nib 文件与视图控制器具有完全相同的名称,则不需要 initWithNibName
    • @aryaxt:确实在这种情况下您不必指定 NIB 名称。但是,IMO 无论如何你都应该使用initWithNibName:bundle:(两个参数都是nil),因为它是UIViewController 的指定初始化程序。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-16
    • 1970-01-01
    • 2016-03-07
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多