什么时候应该使用视图控制器的addSubview方法? [英] When should I use the addSubview method of a view controller?

查看:203
本文介绍了什么时候应该使用视图控制器的addSubview方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iPhone编程,我想知道什么时候使用视图的addSubview方法和何时提交使用模态视图控制器(presentModalViewController)。更复杂的是,如果你正在使用导航控制器(我不是),你可以使用pushViewController方法?



什么时候使用每个和为什么?



感谢。

解决方案

-presentModalViewController -pushViewController 是两种方法来处理同样的事情:显示一个新的视图。您使用哪一个取决于您要去的用户体验。它们对用户意味着不同的东西,但在实现上非常相似。



-addSubview 完全不同。它将组件添加到当前视图。您不应该使用它来显示独立的UI。 -addSubview 最常用于在 -loadView 中以编程方式创建UI时,尽管它还有许多其他用途。 p>

I'm programming for the iPhone and I'm wondering when to use the addSubview method of a view and when to present to use the modal view controller (presentModalViewController). What complicates this even more is if you are using a navigation controller (I'm not) and you can use the pushViewController method?

When would you use each and why?

Thanks.

解决方案

-presentModalViewController and -pushViewController are two ways of going about the same thing: displaying a new view. Which you use depends on the user experience you're going for. They mean different things to the user, but are very similar in implementation.

-addSubview is completely different. It adds components to the current view. You should never use it to display an independent UI. -addSubview is most often used when programmatically creating the UI in -loadView, though it has many other uses.

这篇关于什么时候应该使用视图控制器的addSubview方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆