让 UINavigationController 自动适应它的呈现方式
我正在开发一个可以以模态方式呈现或推入导航堆栈的视图控制器。我将其设为 UINavigationController
子类,以便我免费获得所有 UIToolbar
内容。我可以使用模态方式呈现它:
[self presentModalViewController:myViewController animated:YES];
问题是, UINavigationController
不允许将另一个 UINavigationController
推入其中(有道理),因此这会使其崩溃:
[self.navigationController pushViewController:myViewController animated:YES];
是否有办法检测 myViewController
的呈现方式并自动让它在 UINavigationController
和 UIViewController
之间切换,这样我就不需要 2 个不同的类?
换句话说,myViewController 将能够检测它的呈现方式,并将其推送到以下内容:
[self.navigationController pushViewController:myViewController.topViewController animated:YES];
注意:类似这样的事情可能会做,但它离默认的 UIViewController 行为太远了:
[myViewController pushIntoNavigationController:navController]; // only push myViewController.topViewController
[myViewController presentModallyInParentController:parentController]; // push the whole myViewController
I'm working on a view controller that can be presented modally or pushed into a navigation stack. I made it a UINavigationController
subclass so that I get all the UIToolbar
stuff for free. I can present it modally using:
[self presentModalViewController:myViewController animated:YES];
Problem is, UINavigationController
doesn't allow pushing another UINavigationController
into it (makes sense), so this crashes it:
[self.navigationController pushViewController:myViewController animated:YES];
Would there be a way to detect how myViewController
is presented and automatically have it switch between UINavigationController
and UIViewController
accordingly so that I don't need 2 different classes?
In other words, myViewController would be able to detect how it's getting presented and pushing it would come down to something like:
[self.navigationController pushViewController:myViewController.topViewController animated:YES];
NOTE: Something like this would probably do, but it's getting too far away from the default UIViewController behaviors:
[myViewController pushIntoNavigationController:navController]; // only push myViewController.topViewController
[myViewController presentModallyInParentController:parentController]; // push the whole myViewController
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
myViewController
子类中,创建一个如下所示的方法:这可行吗还是我理解不正确?
In the
myViewController
subclass, create a method something like this:Would this work or am I not understanding correctly?