iPhone:从 Interface Builder 设置控制器变量
我有一个与多个 xib 文件一起使用的视图控制器。目前,我只是在每个 xib 中都有不同的视图出口,并且我根据设置的出口执行不同的操作!但我宁愿做的是在视图控制器上从 Interface Builder 设置一个变量,例如 enum 或 int,它将识别控制器链接到哪个 xib!
无论如何可以做到这一点或者有人可以建议替代方案吗?
我想说,将通用代码提取到一个类中,并且为每个 xib 使用不同的控制器是一种选择,但我宁愿不这样做,因为它会创建更多的文件/代码,然后诚实地需要,因为我的代码几乎相同除了每个 xib 的一些小 switch 语句
I have a view controller that is used with multiple xib files. At the moment I just have a different outlet for the view in each xib, and I do different things based on which of the outlets is set! But what I would rather do is set a variable from Interface Builder on the view controller such as an enum or int which would identify which of the xibs the controller is linked to!
Is there anyway to do this or can someone suggest an alternative?
I will say that extracting the common code into a class and just having different controllers for each xib is an option but I would rather not do it this way as it would create lot more files/code then is honestly needed as the code i almost identical except for a few small switch statements for each xib
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以直接从 Interface Builder 中的属性检查器设置视图的 Tag 属性。然后可以在代码中访问该属性。
文档: http://developer.apple.com/library/ios/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instp/UIView/tag
You can set the Tag property of the view directly from the property inspector in Interface Builder. This property can then be accessed in code.
Documentation: http://developer.apple.com/library/ios/documentation/uikit/reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instp/UIView/tag