ViewController 之间切换时两种方法的区别
在两个视图控制器之间切换时,使用 addSubView
或使用导航控制器与使用 pushViewController
有什么区别?
在我的应用程序中,在游戏计算器启动之前,我在开始时设置了一些屏幕(其中有很多视图切换,并且重用了很多 ViewController)。
在这种情况下,我应该在 AppDelegate 或 RootViewController 中设置导航控制器,还是仅在前几个设置屏幕中使用 addSubView
并在设置后开始计算器视图的位置添加导航控制器屏幕上?
When Switching between two view controllers, what's the difference between addSubView
or using a navigation controller and using pushViewController
?
In my app, I have a few set up screens in the beginning before a game calculator starts (which has a lot of view switching in between, and a lot of ViewControllers are reused).
In that case, should I set up a navigation controller in the AppDelegate or in the RootViewController, or just use addSubView
in the first few set up screens and add a navigation controller where my calculator views start after the set up screens?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不同之处在于,使用
addSubiview
,您可以将一个视图添加到另一个视图,因此另一个视图将包含该视图。导航控制器实际上管理着一个VC堆栈,其中下一个视图不包含在前一个视图中。另一个区别在于参数,
addSubview
将接受视图作为参数,而另一个则接受视图控制器。通常,在显示分层内容(大多数时候在表格视图中)时使用导航控制器,这允许用户更深入地了解细节,或返回到先前的级别。
The difference is that with
addSubiview
, you add a view to another, which therefore will contain it. The navigation controller actually manages a stack of VC, in which the next view isn't included in the previous.Another diference is about parameters,
addSubview
will accept a view as argument, while the other will accept a view controller.Typically, a navigation controller is used when displaying hierarchical content (in a table view most of the time), that allow the user to go deeper in details, or getting back to previous levels.