我正在尝试检查用户是否已登录Facebook。如果是,我想将它们转移到另一个视图。
我遇到的问题是loginViewFetchedUserInfo
和loginViewShowingLoggedInUser
都在视图实际加载之前被调用。
因此,当调用[self showWelcome:self]
时,我会收到“尝试在转换正在进行时开始模态转换”错误。
在将视图发送到新视图之前,我似乎无法想出等待视图加载的方法。
- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView {
// Set flag
isFirstLoginDone = YES;
NSLog(@"User is logged in");
}
- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
user:(id<FBGraphUser>)user {
// Check first login
if(isFirstLoginDone) {
[self showWelcome:self];
}
// clear the flag
isFirstLoginDone = NO;
}
- (IBAction)showWelcome:(id)sender
{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"WelcomeStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"WelcomeController"];
[self presentViewController:vc animated:YES completion:nil];
}
答案 0 :(得分:1)
是的,当一个viewController存在时,当你呈现另一个viewController时会发生这种情况。为此,创建一个虚拟方法,如下面的代码,并用很小的时间间隔激活它。
- (IBAction)showWelcome:(id)sender{
[self someMethod];
}
-(void)someMethod{
if(self.isBeingPresented){
[self performSelector:@selector(someMethod) withObject:nil afterDelay:.1];
}
else{
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"WelcomeStoryboard" bundle:nil];
UIViewController *vc = [mainStoryboard instantiateViewControllerWithIdentifier:@"WelcomeController"];
[self presentViewController:vc animated:YES completion:nil];
}
}