2011-12-16 8 views
0

UISplitViewの詳細ビューで、サブビューをUINavigationControllerの子ビューに追加したいとします。NSTimerを使用してサブビューの表示を遅延させましたが、失敗しました

アニメーションを使用して詳細ビューをフェードインするので、私はNSTimer *delayTimerを使用して子ビューの読み込みを遅延させます。

delayTimer = [NSTimer scheduledTimerWithTimeInterval:1.3 target:self 
selector:@selector(loadWelcomeView) userInfo:nil repeats:NO]; 

私は追加したいビューが

- (void) loadWelcomeView 
{ 
    NSLog(@"Welcome View Loaded."); 
    welcomeViewController = [[WelcomeView alloc] 
         initWithNibName:@"WelcomeView" bundle:nil]; 
    [self.navigationController addChildViewController:welcomeViewController]; 
} 

welcomeviewと呼ばれている。しかし、私はプログラムを実行して待っていたとき、それは完全に空白でした!

ただし、メッセージWelcome view loaded.がデバッグウィンドウに表示されます。

NSTimerを使用する代わりに​​を使用すると、ウェルカムビューが完全に表示されます。

どのような手順が間違っていましたか... ...?

答えて

0

メインスレッドでUIの処理が必要になるため、NSTimersで発生する可能性のあるスレッドの問題を除外しましょう。これを試してみてください:

- (void) loadWelcomeViewWithinMainThread 
{ 
    NSLog(@"Welcome View Loaded."); 
    welcomeViewController = [[WelcomeView alloc] initWithNibName:@"WelcomeView" bundle:nil]; 
    if(welcomeViewController) 
    { 
     if(self.navigationController) 
     { 
      [self.navigationController addChildViewController:welcomeViewController]; 
     } else { 
      NSLog(@"navigationController is null"); 
     } 
    } else { 
     NSLog(@"welcomeViewController is null"); 
    } 
} 

- (void) loadWelcomeViewWithinMainThread { 
    [self performSelectorOnMainThread: @selector(loadWelcomeViewWithinMainThread) withObject: nil waitUntilDone: YES]; 
} 
関連する問題