我的项目在没有 Storyboard的情况下运行,所以我在 AppDelegate 中加载了我的 View :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
self.window.rootViewController = [[SYLoginController alloc] init];
[self.window makeKeyAndVisible];
return YES;
}
它曾经在 iPhone 6 sim 9.3 上工作,但现在,在所有模拟器上它只显示黑屏。但在我的 iPhone 6 设备上它有效。而在另一部 iPhone 6 上,它也显示黑屏。这两款 iPhone 几乎是同一时间购买的 16GB iPhone 6。
在 SYLoginController
的 viewDiDLoad
中,我正在记录其中一个按钮的文本。它只在我的设备上打印文本,在所有模拟器和它打印的其他 iPhone 上打印(空),所以我假设 xib 没有正确加载。
SYLoginController
是一个 UIViewController
,相关的 xib 持有一个 UIView,其 FilesOwner 设置为 SYLoginController
。我真的不明白为什么它只适用于这个特定的设备。我还尝试了 [[SYTabBarController alloc] initWithNibName:@"SYLoginController"bundle:nil]
,这也不起作用...
最佳答案
您是否尝试将它包裹在导航 Controller 周围?
SYLoginController *syVC = [[SYLoginController alloc]initWithNibName:@"SYLoginController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc] syVC];
self.window.rootViewController = nav;
还要再次检查自定义类是否在 XIB 文件中设置为 SYLoginController。 View 连接到文件所有者。
关于ios - Xcode App 有时不会加载 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36871401/