简体   繁体   English

如何从UIViewcontroller加载UIView?

[英]How to load UIView from UIViewcontroller?

I have created a view and now I want to load that view from another viewcontroller without allocating the view . 我创建了一个view ,现在我想从另一个viewcontroller加载该view而不分配view Is it possible or not. 有可能吗? please clarify me. 请澄清我。

I am doing like following 我喜欢跟随

1)Added UIView in viewcontroller.xib and given view class name for the view . 1)在viewcontroller.xib中添加了UIView ,并为view指定了视图类名。

2)created IBOutlet for the view and connected. 2)为view创建IBOutlet并连接。

Now I want to access one property of a view without allocating. 现在我想在不分配的情况下访问view一个属性。 Is it possible to do or not. 有可能做或不做。

If you've created an IBOutlet and hooked up the view, then you are done. 如果你已经创建了一个IBOutlet并连接了视图,那么你就完成了。 The view is allocated when the xib loads and the reference is placed in the IBOutlet. 当xib加载并且引用放在IBOutlet中时,将分配视图。 You can access the view and it's properties through that without doing any allocating yourself. 您可以通过它访问视图及其属性,而无需自行分配。

When your view controller is loaded, your view connected to it (by IBOutlet) also gets loaded. 加载视图控制器后,连接到它的视图(通过IBOutlet)也会被加载。 In this case you have access to all view's property. 在这种情况下,您可以访问所有视图的属性。

Look at "Looading up an XIB" section in this article . 请看“Looading了一个XIB”这部分的文章

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

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