以下代码试图实现一种方法,我的导航控制器在两个不同的视图中启动。问题是每当我的应用程序启动时我都会出现黑屏。
#import "SugarCRMReleaseOneAppDelegate.h"
#import "SettingsViewController.h"
#import "ModuleViewController.h"
@implementation SugarCRMReleaseOneAppDelegate
@synthesize window;
@synthesize navigationController;
#pragma mark -
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after app launch
NSString *a2 = [[NSString alloc] init];
a2 = [[NSUserDefaults standardUserDefaults] objectForKey:@"savedUsername"];
NSString *b2 = [[NSString alloc] init];
b2 = [[NSUserDefaults standardUserDefaults] objectForKey:@"savedPassword"];
[window makeKeyAndVisible];
if(a2 == nil && b2 == nil) {
SettingsViewController *viewController1 = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
[navigationController initWithRootViewController:viewController1];
[window addSubview:[navigationController view]];
[viewController1 release];
}
else {
ModuleViewController *viewController2 = [[ModuleViewController alloc] initWithNibName:@"ModuleViewController" bundle:nil];
[navigationController initWithRootViewController:viewController2];
[window addSubview:[navigationController view]];
[viewController2 release];
}
[UIApplication sharedApplication].idleTimerDisabled=YES;
return YES;
}
答案 0 :(得分:1)
在将块导航控制器视图添加到窗口的if块后面添加以下行:
[window makeKeyAndVisible];
答案 1 :(得分:0)
如果您出现黑屏,则表示您的窗口没有加载。
确保调用了if
个活动,并在将子视图添加到窗口后放置[window makeKeyAndVisible];
。
对我来说很好......
int i = 0;
if(i == 1) {
VideosViewController *viewController1 = [[VideosViewController alloc] initWithNibName:@"VideosViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController1];
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
[viewController1 release];
}
else {
Videos2ViewController *viewController2 = [[Videos2ViewController alloc] initWithNibName:@"Videos2ViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController2];
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
[viewController2 release];
}