具有多个笔尖的单一视图控制器?
我正在尝试构建一个可以“换肤”的视图控制器——也就是说,具有多种外观或个性,但使用单个控制器。每个视图都有相同的按钮等,但我希望能够将每个 nib 文件(皮肤)加载到同一个视图控制器中。我可以创建多个 nib 文件,但我不知道如何连接按钮和操作。我可以为多个 nib 文件指定相同的“文件所有者”吗? (如何?)。
这可以做到吗?
I am trying to construct a view controller that can be 'skinned' -- that is, have multiple appearances or personalities but that uses a single controller. Each view will have the same buttons, etc, but I would like to be able to load each nib file (skin) into the same view controller. I can create multiple nib files, but I don't see how to connect the buttons, and actions. Can I specify the same 'file's owner' for multiple nib files? (HOW?).
Can this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是完全有可能的。只需创建新的 nib 文件,然后在 Interface Builder 中将文件所有者设置为该类。然后,您可以像以前一样连接您的插座和操作。只需在代码中的 initWithNibName: 方法中指定正确的 nib 文件即可。
如果唯一的更改是装饰性的,那么您可能最好只在代码中进行这些更改,但您提出的方法会很好地工作。
This is totally possible. Just create new nib files and in Interface Builder set the file owner to the class. You can then hook up your outlets and actions just like before. From your code just specify the correct nib file in the initWithNibName: method.
If the only changes are cosmetic, you might be better off just making those changes in code, but your proposed method will work just fine.
如果您将 nib 文件内的视图复制并粘贴到同一个 nib 文件中,那么您可以更轻松地完成此操作,这样您就可以在 1 个 nib 文件内拥有 2 个单独的视图。
然后您可以在加载笔尖时在视图之间交换,如下所示:
这将复制所有按钮连接等,这样你就可以摆弄副本而无需再次设置所有内容
you can do it much easier if you literally copy and paste the view inside the nib file into the same nib file, so that you have 2 separate views inside 1 nib file.
then you can swap between the views as you load the nib like so:
this will copy all your button connections etc, so you can just fiddle around with the copy without having to setup everything again