我有一个应用,其初始场景是带有3个标签的标签栏控制器。我创建了一个uitabbarcontroller
类并将其设置为该场景(MainTabViewController
)。
在该课程中,我从viewDidAppear
方法调用presentLogin,该方法为:
- (void)presentLogin{
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
if (![prefs stringForKey:@"storedUser"] && ![prefs stringForKey:@"storedPass"]) {
NSLog(@"No user prefs stored");
// BUT WAIT, before all this, lets pop up a view controller for user registration
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
ModalViewController *popupController = [sb instantiateViewControllerWithIdentifier:@"ModalViewController"];
[self presentViewController:popupController animated:YES completion:nil];
} else {
NSString *storedUser = [NSString stringWithFormat:@"User:%@",[prefs stringForKey:@"storedUser"]];
NSString *storedPass = [NSString stringWithFormat:@"User:%@",[prefs stringForKey:@"storedPass"]];
UIAlertView *internetAlert = [[UIAlertView alloc] initWithTitle:storedUser
message:storedPass
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok", nil];
[internetAlert show];
}
}
但modalVC
由于某种原因没有出现。我得到了这个崩溃日志:
Attempting to begin a modal transition from <MainTabViewController: 0xa55d0d0> to <ModalViewController: 0x15e2b5e0> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed
答案 0 :(得分:3)
我相信你会收到这个错误,因为标签栏控制器在你呈现模态控制器的同时将控制器的视图放在屏幕的第一个标签中。而不是从标签栏控制器中显示它,而是将其显示在第一个选项卡中控制器的viewDidAppear方法中。在没有动画的情况下调用它来查看模态视图控制器而不会看到第一个选项卡控制器。
答案 1 :(得分:1)
尝试添加如下的微小延迟:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self performSelector:@selector(presentLogin) withObject:nil afterDelay:0.1];
}
答案 2 :(得分:0)
tabbarcontroller的视图包含标签栏本身拥有的viewControllers的viewHierarchies。也许是因为某种原因。如果您只将一个viewcontroller设置为tabbar,请尝试查看仍然出现错误。