对 UITabBarController 的开始/结束外观转换的调用不平衡

发布于 2024-12-22 04:59:03 字数 2478 浏览 3 评论 0原文

我有一个 UITabBarController,在初始运行时,我想覆盖一个登录视图控制器,但收到错误。

对开始/结束外观转换的不平衡调用<< UITabBarController:0x863ae00>。

下面是代码。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    // Override point for customization after application launch.

    UIViewController *lessonVC = [[[LessonViewController alloc] initWithNibName:@"LessonViewController" bundle:nil] autorelease];

    UIViewController *programVC = [[[ProgramViewController alloc] initWithNibName:@"ProgramViewController" bundle:nil] autorelease];

    UIViewController *flashcardVC = [[[FlashCardViewController alloc] initWithNibName:@"FlashCardViewController" bundle:nil] autorelease];

    UIViewController *moreVC = [[[MoreViewController alloc] initWithNibName:@"MoreViewController" bundle:nil] autorelease];

    UINavigationController *lessonNVC = [[[UINavigationController alloc] initWithRootViewController:lessonVC] autorelease];

    UINavigationController *programNVC = [[[UINavigationController alloc] initWithRootViewController:programVC] autorelease];

    UINavigationController *flashcardNVC = [[[UINavigationController alloc] initWithRootViewController:flashcardVC] autorelease];

    UINavigationController *moreNVC = [[[UINavigationController alloc] initWithRootViewController:moreVC] autorelease];

    self.tabBarController = [[[UITabBarController alloc] init/*WithNibName:nil bundle:nil*/] autorelease];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:lessonNVC, programNVC, flashcardNVC, moreNVC, nil];
    self.tabBarController.selectedIndex = 0;
    self.window.rootViewController = self.tabBarController;

    [self.window makeKeyAndVisible];

    if (![[ZYHttpRequest sharedRequest] userID]) 
    {
        // should register or login firstly
        LoginViewController *loginVC = [[LoginViewController alloc] initWithNibName:@"LoginViewController"
                                                                             bundle:nil];
        loginVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self.tabBarController presentModalViewController:loginVC animated:YES];
        ZY_SAFE_RELEASE(loginVC);
    }

    return YES;
}

谁能帮助我?提前致谢!

I have an UITabBarController, when initial run, I want to overlay a login view controller but received error.

Unbalanced calls to begin/end appearance transitions for < UITabBarController: 0x863ae00 >.

Below is the code.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    // Override point for customization after application launch.

    UIViewController *lessonVC = [[[LessonViewController alloc] initWithNibName:@"LessonViewController" bundle:nil] autorelease];

    UIViewController *programVC = [[[ProgramViewController alloc] initWithNibName:@"ProgramViewController" bundle:nil] autorelease];

    UIViewController *flashcardVC = [[[FlashCardViewController alloc] initWithNibName:@"FlashCardViewController" bundle:nil] autorelease];

    UIViewController *moreVC = [[[MoreViewController alloc] initWithNibName:@"MoreViewController" bundle:nil] autorelease];

    UINavigationController *lessonNVC = [[[UINavigationController alloc] initWithRootViewController:lessonVC] autorelease];

    UINavigationController *programNVC = [[[UINavigationController alloc] initWithRootViewController:programVC] autorelease];

    UINavigationController *flashcardNVC = [[[UINavigationController alloc] initWithRootViewController:flashcardVC] autorelease];

    UINavigationController *moreNVC = [[[UINavigationController alloc] initWithRootViewController:moreVC] autorelease];

    self.tabBarController = [[[UITabBarController alloc] init/*WithNibName:nil bundle:nil*/] autorelease];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:lessonNVC, programNVC, flashcardNVC, moreNVC, nil];
    self.tabBarController.selectedIndex = 0;
    self.window.rootViewController = self.tabBarController;

    [self.window makeKeyAndVisible];

    if (![[ZYHttpRequest sharedRequest] userID]) 
    {
        // should register or login firstly
        LoginViewController *loginVC = [[LoginViewController alloc] initWithNibName:@"LoginViewController"
                                                                             bundle:nil];
        loginVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self.tabBarController presentModalViewController:loginVC animated:YES];
        ZY_SAFE_RELEASE(loginVC);
    }

    return YES;
}

Anyone who can help me? Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

卸妝后依然美 2024-12-29 04:59:03

您需要等到下一个运行循环才呈现模式视图控制器。我最终使用了一个块(让事情变得更简单)来安排下一个运行循环的演示:

更新:
正如 Mark Amery 下面提到的,只需一个简单的 dispatch_async 即可工作,不需要计时器:

dispatch_async(dispatch_get_main_queue(), ^(void){     
  [self.container presentModalViewController:nc animated:YES]; 
});

/* Present next run loop. Prevents "unbalanced VC display" warnings. */
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self.container presentModalViewController:nc animated:YES];
});

You need to wait to present the modal view controller until the next run loop. I ended up using a block (to make things more simple) to schedule the presentation for the next run loop:

Update:
As mentioned by Mark Amery below, just a simple dispatch_async works, there's no need for a timer:

dispatch_async(dispatch_get_main_queue(), ^(void){     
  [self.container presentModalViewController:nc animated:YES]; 
});

/* Present next run loop. Prevents "unbalanced VC display" warnings. */
double delayInSeconds = 0.1;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    [self.container presentModalViewController:nc animated:YES];
});
三五鸿雁 2024-12-29 04:59:03

我怀疑问题是您试图在标签栏加载完成之前调用 presentModalViewController: 。尝试将最终逻辑移至下一个事件循环:

  [self.window makeKeyAndVisible];
  [self performSelector:(handleLogin) withObject:nil afterDelay:0];
}

- (void)handleLogin
{
  if (![[ZYHttpRequest sharedRequest] userID]) 
    {
        // should register or login firstly
        LoginViewController *loginVC = [[LoginViewController alloc] initWithNibName:@"LoginViewController"
                                                                             bundle:nil];
        loginVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self.tabBarController presentModalViewController:loginVC animated:YES];
        ZY_SAFE_RELEASE(loginVC);
    }
}

I suspect the problem is that you're trying to call presentModalViewController: before the tab bar is done loading. Try moving the final logic onto the next event loop:

  [self.window makeKeyAndVisible];
  [self performSelector:(handleLogin) withObject:nil afterDelay:0];
}

- (void)handleLogin
{
  if (![[ZYHttpRequest sharedRequest] userID]) 
    {
        // should register or login firstly
        LoginViewController *loginVC = [[LoginViewController alloc] initWithNibName:@"LoginViewController"
                                                                             bundle:nil];
        loginVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
        [self.tabBarController presentModalViewController:loginVC animated:YES];
        ZY_SAFE_RELEASE(loginVC);
    }
}
在巴黎塔顶看东京樱花 2024-12-29 04:59:03
[self.tabBarController presentModalViewController:loginVC animated:**NO**];
[self.tabBarController presentModalViewController:loginVC animated:**NO**];
逆流 2024-12-29 04:59:03

当我尝试在主视图的 viewWillAppear 中呈现 ModalViewController (我的欢迎屏幕)时,我遇到了类似的问题。只需将模态 VC 调用移至 viewDidAppear 即可解决此问题。

I had a similar problem when tried to presentModalViewController (my welcome screen) in main view's viewWillAppear. Is was solved just by moving the modal VC call to viewDidAppear.

一城柳絮吹成雪 2024-12-29 04:59:03
[self performSelector:@selector(modaltheView) withObject:self afterDelay:0.1];
-(void)modaltheView
{
    [self.container presentModalViewController:nc animated:YES];
}
[self performSelector:@selector(modaltheView) withObject:self afterDelay:0.1];
-(void)modaltheView
{
    [self.container presentModalViewController:nc animated:YES];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文