0

在 中的详细视图中UISplitView,我想将子视图添加到其UINavigationController子视图中。

我使用 anNSTimer *delayTimer来延迟子视图的加载,因为我使用动画淡入详细视图。

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

我要添加的视图称为welcomeview

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

但是当我运行程序并等待时,它完全是空白的!!!

但是,消息Welcome view loaded.WAS 显示在调试窗口中。

如果我使用[self loadWelcomeView];而不是使用NSTimer,欢迎视图将完美显示。

我做错了什么程序...?

4

1 回答 1

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];
}
于 2011-12-16T19:00:30.677 回答