[英]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.