ios - Objective C - 当前模态视图之后根 Controller 不正确

标签 ios objective-c ios7

第一个 View 的名称是IntroPage。 第二个 View 的名称是 Search。 在 viewDidAppear 中,我使用以下代码:

Search *search = [self.storyboard instantiateViewControllerWithIdentifier:@"searchPage"];
search.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentViewController:search animated:YES completion:nil];

一切正常,但是当我想查看当前 View 时

[UIApplication sharedApplication].keyWindow.rootViewController;

他告诉我当前 View 是“Intro”而不是“Search”,这会导致很多错误。

当我将代码更改为:

[self performSegueWithIdentifier:@"SearchPage" sender:self];

问题已解决,但我无法使用此代码,因为我需要通过转换添加更多属性。

最佳答案

根据您添加的代码,Search 将成为 Intro 的 modalViewController。这并不意味着 search 将是一个 rootViewController。

如果要更改 rootViewController,则必须将 Search 设置为 rootViewController。

[[UIApplication sharedApplication] keyWindow] setRootViewController:search];

关于ios - Objective C - 当前模态视图之后根 Controller 不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25355373/

相关文章:

objective-c - 如何产生具有特定频率的声音(并能够更改频率)

objective-c - 无法到达 navigationController,但应该可以。你能发现错误吗?

swift - 覆盖 UILabel setText : method in Swift

ios - 为什么滑动手势识别器会 swift 出错?

ios - 使用 Swift 在 Firebase 中检索子数组

iphone - 如何让ui始终响应并进行后台更新?

ios - 向下滚动时,UICollectionView 中的图像会自动翻转吗?

iphone - 使用 UIImagePickerController 以特定分辨率捕获照片

ios - 使用 jQuery Mobile 创建 iOS 页面指示器(点)

iphone - 类似于ios7打开应用的动画