简体   繁体   English

UIViewController拥有另一个UIViewController

[英]UIViewController owns another UIViewController

Here's the scenario. 这是场景。

When a user's login info is submitted, 提交用户的登录信息后,
activityIndicator view is shown. 显示activityIndi​​cator视图。

This could be implemented as.. 这可以实现为..
LoginViewController can possess LoadingViewController whose view is activityIndicator. LoginViewController可以拥有其视图为activityIndi​​cator的LoadingViewController。
addSubview/removeFromSuperview at appropriate time. 在适当的时间addSubview / removeFromSuperview。

I would normally just create a activityIndicator view programmatically and play along. 我通常只是以编程方式创建一个activityIndi​​cator视图并进行操作。
I guess the LoadingViewController could come into play when programmers want every view to be associated with an xib. 我猜想,当程序员希望每个视图都与一个xib相关联时,LoadingViewController可能会发挥作用。

UIViewController having UIViewController seems normal? 有UIViewController的UIViewController似乎正常吗?
If not, how would you handle the above case when your teammates want every view to be visible in some XIB? 如果不是,当队友希望每个视图在某些XIB中可见时,您将如何处理上述情况?

UIViewController subviews the view of another UIViewController is normal. UIViewController子视图另一个UIViewController的视图是正常的。 Your method will work. 您的方法将起作用。

Alternatively, you can put the ActivityIndicatorView as subview of LoginViewController , and hide/unhide it (hide by default). 或者,您可以将ActivityIndicatorView放置为LoginViewController子视图,然后将其隐藏/取消隐藏(默认情况下为隐藏)。 No need to create a separate view controller just for it. 无需为此创建单独的视图控制器。 This is method is not good if you are very tight on memory (I have some doubt on this, though). 如果您对内存的要求非常严格,则此方法不好(不过对此我有些怀疑)。

If you are very tight on memory, just convince them to let you create it programmatically. 如果您对内存非常紧张,只需说服他们让您以编程方式创建它即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM