我有三个View Controller VC1,VC2和VC3。
VC2是第三方库,它出现在VC1上。
然后VC2解散自己并向VC1发送回调,VC1尝试自己呈现VC3但是失败了。
在解雇VC2后,有没有办法立即呈现VC3?
-(void)onDismisLoginVC{
MessageVC *messageVC = [[MessageVC alloc] initWithNibName:@"MessageVC" bundle:nil];
[self.navigationController presentViewController:messageVC animated:YES completion:NULL];
}
不幸的是我无法在VC2中使用^completion
块解除显示的viewcontroller,因为我只是接收到这个方法的回调而无法编辑VC2的代码。
答案 0 :(得分:6)
我知道我们总是把nil
放到完成块中......但它实际上确实有用。我向你保证。
[self dismissViewControllerAnimated:YES completion:^{
//code to be executed with the dismissal is completed
// for example, presenting a vc or performing a segue
}];
答案 1 :(得分:5)
这是我用来解雇Facebook登录视图控制器的那个。
UIViewController *theTrick = self.presentingViewController;
UIViewController *toPresent = [self.storyboard instantiateViewControllerWithIdentifier:@"toPresentViewController"];
[self dismissViewControllerAnimated:YES completion:^{
[theTrick presentViewController:toPresent animated:YES completion:nil];
}];
答案 2 :(得分:-2)
谢谢你的帮助。在呈现VC3之前添加一点延迟解决了这个问题。
-(void)onDismisLoginVC{
[self performSelector:@selector(presentMessageVC) withObject:self afterDelay:1];
}
-(void)presentMessageVC
{
MessageVC *messageVC = [[MessageVC alloc] initWithNibName:@"MessageVC" bundle:nil];
[self.navigationController presentViewController:messageVC animated:YES completion:NULL];
}