在运行时检测presentedViewController
浏览 iOS 5 文档,我注意到 modalViewController 已被弃用,而不是presentedViewController。我想到使用:
[viewController respondsToSelector:@selector(presentedViewController)];
查看 getter 是否存在并在支持时使用presentedViewController。
这是在 iOS5+ 中检测此功能的正确方法吗?或者有更好的方法吗?
Looking through the iOS 5 documentation I noticed that modalViewController was deprecated in place of presentedViewController. I thought of using:
[viewController respondsToSelector:@selector(presentedViewController)];
To see if the getter was present and use presentedViewController when it's support.
Is this the correct way of detecting this functionality in iOS5+? or is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一些包含代码在 iOS4 上是私有的,这意味着仅使用 respondsToSelector 进行检查可能并不总是有效。我不能 100% 确定它是否会在您的情况下失败,但我仍然建议检查当前版本是否为 iOS5 或更高版本。这是一种更强大且面向未来的方法,可确保您没有在早期版本中使用特定于 iOS5 的代码。
Some of the containment code is private on iOS4 meaning that just checking with respondsToSelector might not always work. I'm not 100% sure if it will fail in your case but I would still recommend to check if the current version is iOS5 or higher. It is a more robust and future proof way to make sure you are not using iOS5-specific code in an earlier version.