我在运行应用时收到NSLog
消息,但nextviewcontroller
(欢迎页面)没有出现,我想第一次呼叫nextviewcontroller
继续操作。此屏幕只有在我们第一次跑步时才会出现。条件正在运行,但nextviewcontroller
未来。我使用此代码
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Configure logging framework
[DDLog addLogger:[DDTTYLogger sharedInstance]];
// Setup the XMPP stream
[self setupStream];
// Override point for customization after application launch.
BOOL launch = [[NSUserDefaults standardUserDefaults] boolForKey:@"LaunchingFirstTime"];
if(!launch){
NSLog(@"first");
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"LaunchingFirstTime"];
[[NSUserDefaults standardUserDefaults] synchronize];
self.viewController1 = [[welcomePage alloc] initWithNibName:@"welcomePage" bundle:nil];
self.window.rootViewController = self.viewController1;
}
else{
NSLog(@"second");
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
}
[self.window makeKeyAndVisible];
if (![self connect])
{
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0.0 * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
//messageTableViewController
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
//[navigationController presentModalViewController:settingsViewController animated:YES];
});
}
return YES;
答案 0 :(得分:0)
如果您没有使用故事板,并且您的窗口不是IBOutlet,请执行此操作。
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//add this
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor=[UIColor clearColor];
BOOL launch = [[NSUserDefaults standardUserDefaults] boolForKey:@"LaunchingFirstTime"];
if(!launch){
NSLog(@"first");
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"LaunchingFirstTime"];
self.viewController1 = [[welcomePage alloc] initWithNibName:@"welcomePage" bundle:nil];
self.window.rootViewController = self.viewController1;
}
else{
NSLog(@"second");
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
}
答案 1 :(得分:0)
如果您使用的是UIStoryBoard
,请尝试使用此
`instantiateViewControllerWithIdentifier` .: application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BOOL launch = [[NSUserDefaults standardUserDefaults] boolForKey:@"LaunchingFirstTime"];
if(!launch){
NSLog(@"first");
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"LaunchingFirstTime"];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
ViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"ViewController_ID"];
self.window.rootViewController = self.viewController1;
}
else{
NSLog(@"second");
self.viewController = // Follow the above
self.window.rootViewController = self.viewController;
}
如果您不使用故事板,请简要描述您的问题,<。p>
答案 2 :(得分:0)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
BOOL launch = [[NSUserDefaults standardUserDefaults] boolForKey:@"LaunchingFirstTime"];
if(!launch){
NSLog(@"first");
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"LaunchingFirstTime"];
[[NSUserDefaults standardUserDefaults] synchronize];
self.viewController1 = [[welcomePage alloc] initWithNibName:@"welcomePage" bundle:nil];
self.window.rootViewController = self.viewController1;
} else {
NSLog(@"second");
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
}
}
答案 3 :(得分:0)
使用synchronize
方法立即将用户默认值写入磁盘。
[[NSUserDefaults standardUserDefaults] synchronize];
来自Apple Docs:
synchronize method writes any modifications to the persistent domains to disk and updates all unmodified persistent domains to what is on disk.
您的代码中缺少它。将其写在if
子句中。