
[英]dismissModalViewControllerAnimated makes my app crash :(
[英]After dismissModalViewControllerAnimated: my tabbar disappears
我有一个包含三层视图控制器的应用程序:UITabBarController => UINavigationController => UIViewController。 它们都是用代码而不是使用IB生成的。 根据通常的设计准则,选项卡栏位于底部。 在我的UIViewController中,我使用以下代码来呈现modalViewController:
myModalVC = [[MyModalViewController alloc] init];
[self.navigationController presentModalViewController:myModalVC animated:YES];
这项工作正常,然后弹出模式视图控制器并覆盖整个屏幕。
但是,当在模态视图控制器中按下按钮时,我运行以下命令:
[self dismissModalViewControllerAnimated:YES];
模态视图控制器会动画。 但是,我可以看到原始的UIViewcontroller视图,但是选项卡栏完全消失了。 我已经在Google上搜索了很多,但找不到任何遇到相同问题的人。
您应该将模态视图控制器委派给父视图控制器。 [self dismissModalViewControllerAnimated:YES];
应该由委托而不是模式视图本身完成,父视图负责关闭模式视图。
其实我是通过更多搜索而发现的。 我将选项卡栏控制器设为应用程序委托的属性,当它呈现模式vc时,它将执行此操作
UIApplication *myApp = [UIApplication sharedApplication];
noIBAppDelegate*appDelegate = (noIBAppDelegate*)myApp.delegate;
[appDelegate.tabBarController presentModalViewController:myModalVC animated:YES];
然后通过这段代码将其消除
UIApplication *myApp = [UIApplication sharedApplication];
noIBAppDelegate*appDelegate = (noIBAppDelegate*)myApp.delegate;
[appDelegate.tabBarController dismissModalViewControllerAnimated:YES];
这修复了选项卡栏消失的问题。
感谢您的回答! 我遇到了同样的问题,但是我正在用Swift编写程序,因此以为我会包括我从查看您的解决方案中得出的解决方案。 我只需要使用这两行就可以解决问题。 不需要什么了。
tabBarController?.presentViewController(viewController, animated: true, completion: nil)
和
tabBarController?.dismissViewControllerAnimated(true, completion: nil)
我还应该提到这一行:tabBarController?.delegate = self,在我的NavigationController的viewDidLoad函数中。
尝试
[self.navigationController dismissModalViewControllerAnimated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.