简体   繁体   English

在Interface Builder故事板上创建UIView

[英]Create UIView in Interface Builder Storyboard

I have searched for what I want to do but all the answers seem to predate storyboards in iOS, so i'm hoping there is a new and easier way to do it. 我已经搜索了我想做的事,但所有答案似乎都早于iOS中的故事板,因此我希望有一种新的且更轻松的方法。

I have a view controller that needs the same UIView multiple times. 我有一个视图控制器,需要多次使用相同的UIView。 I could create and position them programatically but it would really help me if I could design them in a storyboard and position them visually there. 我可以以编程方式创建和放置它们,但是如果我可以将它们设计在情节提要中并在视觉上放置它们,那将对我有很大帮助。 I would prefer not to create an extra .xib file. 我不想创建一个额外的.xib文件。

I am developing for iOS 6 and there is a new Container View but i cannot seem to understand how it works, maybe somebody can explain it to me. 我正在为iOS 6开发,并且有一个新的Container View,但是我似乎无法理解它的工作原理,也许有人可以向我解释一下。 I managed to make the view appear but I cannot communicate between the UIView in the container and the parent UIViewController. 我设法使视图出现,但无法在容器中的UIView与父UIViewController之间进行通信。 I have also seen a way to do this with segues but they said that they shouldn't be used in that way. 我也看到了使用segue进行此操作的方法,但是他们说不应以这种方式使用它们。

No trick, no gimmick 没有把戏,没有头

@Chiquis solution is the way to go. @Chiquis解决方案是必经之路。

Treat Storyboard as a set of XIB , all neatly organized under a single roof: 将Storyboard视为一组XIB ,将它们整齐地组织在一个屋顶下:

  1. Copy and paste your UIView in as many UIViewController as you see fit 将UIView复制并粘贴到尽可能多的UIViewController
  2. Connect each UIView to its parent UIViewController using IBOutlets 使用IBOutlets将每个UIView连接到其父UIViewController

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

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