我目前正在为我的公司开发一个 iPhone 应用程序,我遇到了一件奇怪的事情。
我的 View 层次结构如下所示:
UITabBarController 包含 5 个选项卡,每个选项卡包含一个 UINAvigationController。 到目前为止一切正常。
现在我想通过 presentModalViewController 方法在 UITabBarController 使用这行代码:
-(void)callFilterOptions
{
FilterOptionsView *filterView = [[FilterOptionsView alloc] init];
[filterView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self.tabBarController presentModalViewController:filterView animated:TRUE];
}
FilterOptionsView 是一个普通的 UIViewController,只包含黑色背景 时刻。
发生的事情是 View 出现,几秒钟后神秘地消失了。 为什么会这样?我绝不会调用 dismissModalViewController 方法。
我在介绍邮件编辑器时已经遇到过这个问题。
问候, 弗洛里安
最佳答案
UINavigationController *myNavController = [self navigationController];
[myNavController presentModalViewController:filterView animated:TRUE];
或者更好的方法可能是:
UIApplication *myApp = [UIApplication sharedApplication];
noIBAppDelegate*appDelegate = (noIBAppDelegate*)myApp.delegate;
[appDelegate.tabBarController presentModalViewController:filterView animated:YES];
解雇:
UIApplication *myApp = [UIApplication sharedApplication];
noIBAppDelegate*appDelegate = (noIBAppDelegate*)myApp.delegate;
[appDelegate.tabBarController dismissModalViewControllerAnimated:YES];
附注我建议不要将 View Controller 命名为“filterView”,最好命名为“filterViewController”
关于iphone - presentModalViewController - ViewController 在呈现后自动消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9195830/