Ann*_*una 6 objective-c uiviewcontroller ios
在我MainViewController,我通过这个提出另一个视图控制器:
MessageViewController *messageController = [[MessageViewController alloc]initWithNibName:nil bundle:nil];
[messageController setModalPresentationStyle:UIModalPresentationFullScreen];
[messageController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:messageController animated:YES completion:nil];
[messageController release];
Run Code Online (Sandbox Code Playgroud)
这将正确显示视图控制器.但是,当我尝试返回到呈现视图控制器时,在这种情况下应该是MainViewController,这段代码不起作用:
if ([self.presentingViewController isKindOfClass:[MainViewController class]])
[(MainViewController *)self.presentingViewController setCurrentViewTag:2];
[self dismissModalViewControllerAnimated:YES];
Run Code Online (Sandbox Code Playgroud)
我删除了"if .."条件以强制它设置当前视图标记.发生错误告诉我呈现视图控制器似乎是UINavigationController:
[UINavigationController setCurrentViewTag:]: unrecognized selector sent to instance 0x8352a50
Run Code Online (Sandbox Code Playgroud)
谁能告诉我为什么会这样?这段代码之前曾经工作过,我不确定是什么改变了它使它停止正常工作.
编辑
这是更新的代码:
ReaderController *readerController = [[ReaderController alloc]initWithNibName:nil bundle:nil];
[readerController loadWhichViewToShow:2];
[self setDefinesPresentationContext:YES];
[readerController setModalPresentationStyle:UIModalPresentationFullScreen];
[readerController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentViewController:readerController animated:YES completion:nil];
[readerController release];
Run Code Online (Sandbox Code Playgroud)
Tob*_*obi 14
调用[self presentViewController:messageController animated:YES completion:nil];不一定使用你调用它的vc来呈现另一个vc.默认情况下,它沿vc层次结构向上移动,并在根视图控制器上显示另一个vc.这就是为什么在你的情况下,呈现视图控制器是一个UINavigationController.
如果你想强制你的MainViewController成为呈现vc,你有电话:
[self setDefinesPresentationContext:YES];
Run Code Online (Sandbox Code Playgroud)
在呈现MessageViewController之前在MainViewController上.
编辑:如果其他人读到这个:definesPresentationContext似乎被窃听或文档错误.请参阅下面的评论和Cocoa Builder
我对这个问题的回答的副本
来自Programming iOS 6,作者Matt Neuburg:
在iPad上,当显示的视图控制器的modalPresentationStyle为UIModalPresentationCurrentContext时,必须确定哪个视图控制器应作为显示的视图控制器的presentingViewController。这将确定将由呈现的视图控制器的视图替换哪个视图。该决定涉及另一个UIViewController属性definePresentationContext(一个BOOL)。从将presentViewController:animated:completion:发送到的视图控制器开始,我们沿着父级视图控制器的链,寻找其definePresentationContext属性为YES的视图控制器。如果我们找到一个,那就是那个。它将是presentingViewController,其视图将由所呈现的视图控制器的视图替换。如果我们找不到一个,
TL; DR
1组definesPresentationContext对真正期望的presentingViewController
2组modalPresentationStyle至UIModalPresentationCurrentContext所期望的presentedViewController
| 归档时间: |
|
| 查看次数: |
4822 次 |
| 最近记录: |