[英]next view controller is not appearing when i launched apps
我在运行应用程序时收到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;
如果您不使用情节提要,并且您的窗口不是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;
}
如果您使用的是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;
}
如果您不使用情节提要,请简要描述您的问题。
- (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;
}
}
使用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
子句中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.