这是来自应用程序委托(delegate)的我的 applicationDidLaunch 方法:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];
//This hides the status bar throughout the app.
[UIApplication sharedApplication].statusBarHidden=YES;
NSMutableArray *tabItems = [[NSMutableArray alloc] initWithCapacity:5];
GHHaikuViewController *hvc = [[GHHaikuViewController alloc] init];
hvc.tabBarItem.title = @"Home";
hvc.tabBarItem.image = [UIImage imageNamed:@"53-house.png"];
[tabItems addObject:hvc];
GHComposeViewController *cvc = [[GHComposeViewController alloc] init];
cvc.tabBarItem.title = @"Compose";
cvc.tabBarItem.image = [UIImage imageNamed:@"216-compose.png"];
[tabItems addObject:cvc];
GHWebViewController *wvc = [[GHWebViewController alloc] init];
wvc.tabBarItem.title = @"Buy";
wvc.tabBarItem.image = [UIImage imageNamed:@"80-shopping-cart.png"];
[tabItems addObject:wvc];
GHFeedback *fvc = [[GHFeedback alloc] init];
fvc.tabBarItem.title = @"Feedback";
fvc.tabBarItem.image = [UIImage imageNamed:@"18-envelope.png"];
[tabItems addObject:fvc];
GHSettingsViewController *svc = [[GHSettingsViewController alloc] init];
svc.tabBarItem.title = @"Settings";
svc.tabBarItem.image = [UIImage imageNamed:@"20-gear-2.png"];
[tabItems addObject:svc];
UITabBarController *tbc = [[UITabBarController alloc] init];
tbc.viewControllers = tabItems;
self.window.rootViewController = tbc;
return YES;
}
这里是来自第一个 View Controller 的 viewDidLoad
,为清楚起见进行了简化:
-(void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
background.backgroundColor = [UIColor whiteColor];
[self.view addSubview:background];
NSLog(@"View loaded.");
}
在 iPhone 上一切正常。在 iPad(或至少是模拟器)上,“查看已加载”日志,但不是白屏,而是黑屏。早些时候我在玩 iPad 的 Storyboard,但我删除了它并且我想我删除了所有文件,现在一切都从代码运行。我已经清理了项目。我忽略了什么?
编辑:这是 Xcode 中目标摘要的截图。
最佳答案
如果您不使用主 Storyboard或 xib,则需要在代码中创建 UIWindow
:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
关于ios - 应用程序在 iPhone 上运行良好; iPad模拟器只给出黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14366754/