gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 18:16:31 25 4
gpt4 key购买 nike

我有一个 UITabBarController,在初始运行时,我想覆盖一个登录 View Controller ,但收到错误。

Unbalanced calls to begin/end appearance transitions for < 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;
}

谁能帮帮我?提前致谢!

最佳答案

您需要等待下一次运行循环才能呈现模态视图 Controller 。我最终使用了一个 block (为了让事情变得更简单)来安排下一个运行循环的演示:

更新:
正如下面 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];
});

关于iphone - 对 UITabBarController 的开始/结束外观转换的调用不平衡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8563473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com