我正在检查用户是否登录到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];
}发布于 2014-02-22 17:58:43
是的,当您在出现一个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];
}
}https://stackoverflow.com/questions/21958026
复制相似问题