Неуравновешенные вызовы для перехода на начало/конец для UITabBarController
У меня есть 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;
}
Кто может мне помочь? Спасибо заранее!
Ответы
Ответ 1
Вам нужно подождать, пока не появится контроллер модального представления, до следующего цикла цикла. Я закончил использование блока (чтобы сделать вещи более простыми), чтобы запланировать презентацию для следующего цикла цикла:
Update:
Как уже упоминалось, Марк Эмери ниже, просто простая 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];
});
Ответ 2
Я подозреваю, что проблема заключается в том, что вы пытаетесь вызвать 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);
}
}
Ответ 3
[self.tabBarController presentModalViewController:loginVC animated:**NO**];
Ответ 4
У меня была аналогичная проблема при попытке представитьModalViewController (экран приветствия) в главном представлении viewWillAppear. Решено только путем перемещения модального вызова VC в viewDidAppear.
Ответ 5
[self performSelector:@selector(modaltheView) withObject:self afterDelay:0.1];
-(void)modaltheView
{
[self.container presentModalViewController:nc animated:YES];
}