xcode -self parentViewController-dismissModalViewController 不适用于 iOS 5
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7849472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
-self parentViewController- dismissModalViewController not working on iOS 5
提问by Stephen Lynx
So, any clue on this? I had to use [self dismiss modalviewcontroller to dismiss modalviews. Funny fact: when dismissing a tabbarcontroller I could still use the reference to parentviewcontroller, when dismissing a regular viewcontroller, not.
那么,这有什么线索吗?我不得不使用 [自我关闭 modalviewcontroller 来关闭 modalviews。有趣的事实:在解除 tabbarcontroller 时,我仍然可以使用对 parentviewcontroller 的引用,而在解除常规视图控制器时则不能。
回答by Jason
On iOS 5 you will need to use the presentingViewController
selector instead of the parentViewController
selector.
在 iOS 5 上,您需要使用presentingViewController
选择器而不是parentViewController
选择器。
回答by UPT
-(UIViewController *)getParentViewController{
float currentVersion = 5.0;
float sysVersion = [[[UIDevice currentDevice] systemVersion] floatValue];
if (sysVersion >= currentVersion) {
// iOS 5.0 or later version of iOS specific functionality hanled here
return self.presentingViewController;
}
else {
//Previous than iOS 5.0 specific functionality
return self.parentViewController;
}
}
回答by pterodax
The app i have in the store was built using ios SDK 4.3 and uses self.parentViewController dismissModalViewControllerAnimated:YES
. It continues to work with IOS 5 devices. I thought it would since it was built on sdk 4.3. Now when i'm updating it with the new xcode and ios 5.0 sdk, it will not work as is and i have to change all the view closing stuff to use the conditional selector workaround mentioned above.(yuck!)
我在商店中的应用程序是使用 ios SDK 4.3 构建的,并使用self.parentViewController dismissModalViewControllerAnimated:YES
. 它继续适用于 IOS 5 设备。我认为它会,因为它是建立在 sdk 4.3 上的。现在,当我使用新的 xcode 和 ios 5.0 sdk 更新它时,它将无法正常工作,我必须更改所有视图关闭内容以使用上面提到的条件选择器解决方法。(糟糕!)
Just thought i'd mention that dismissing from the parent should work on ios 5 (at least in my case with the ios 4.3 sdk). I can't speak for previous sdks or other selectors with parentViewController.
只是想我会提到从父级解雇应该适用于 ios 5(至少在我使用 ios 4.3 sdk 的情况下)。我不能说以前的 sdks 或其他带有 parentViewController 的选择器。
回答by Tanin
I have built a category that add presentingViewController
on iOS 4.
我已经建立了一个添加presentingViewController
到 iOS 4的类别。
It disables itself on iOS 5.
它在 iOS 5 上禁用自身。
You can use it seamlessly. Please see backward-modal.
您可以无缝使用它。请参阅向后模态。
回答by DUzun
I found a nice blog post explaining this issue:
我找到了一篇很好的博客文章,解释了这个问题:
http://omegadelta.net/2011/11/04/oh-my-god-they-killed-parentviewcontroller/
http://omegadelta.net/2011/11/04/oh-my-god-they-killed-parentviewcontroller/
Following this post I created a category method for UIViewController:
在这篇文章之后,我为 UIViewController 创建了一个类别方法:
- (UIViewController*) myParentViewController {
UIViewController* ret = [self parentViewController];
if(ret == nil) {
if([self respondsToSelector:@selector(presentingViewController)]) {
ret = [self presentingViewController];
}
}
return ret;
}
回答by Ivan Vu?ica
For your particular use case of dismissing the modal view controller, you may want to keep in mind the second paragraphof the Discussion section in Apple's documentation for -dismissModalViewControllerAnimated:
.
对于您取消模态视图控制器的特定用例,您可能需要记住Apple 文档中讨论部分的第二段-dismissModalViewControllerAnimated:
。
The parent view controller is responsible for dismissing the modal view controller it presented using the presentModalViewController:animated: method. If you call this method on the modal view controller itself, however, the modal view controller automatically forwards the message to its parent view controller.
If you call this method on the modal view controller itself, however, the modal view controller automatically forwards the message to its parent view controller.
父视图控制器负责关闭它使用 presentModalViewController:animated: 方法呈现的模态视图控制器。但是,如果您在模态视图控制器本身上调用此方法,则模态视图控制器会自动将消息转发到其父视图控制器。
但是,如果您在模态视图控制器本身上调用此方法,则模态视图控制器会自动将消息转发到其父视图控制器。
Jason's solution is also great and helpful! Thanks!
Jason 的解决方案也很棒而且很有帮助!谢谢!