强制 Interface Builder 更改对象类(UIButton->UIControl)
我有一个 UIView,里面充满了按钮,这些按钮都很好地连接到了操作和出口。然而,以我无限的智慧,我决定我真的宁愿让按钮行为有所不同,并将其子类化为 UIControl。
我的计划是跳入 Interface Builder,将按钮的类更改为我的新 UIControl 子类,然后启动并运行。这将保留所有插座和动作连接。
在 IB(View Identity Inspector)中,当我在类字段中输入 UIControl 子类时,当我退出时它会恢复为 UIButton。任何 UIButton 子类都可以,但 UIControl 不行。我可以沿着继承树向下移动,但不能向上移动...
第一个计划是转到 XCode 并将新控件的超类临时更改为 UIButton,更改 IB 按钮的“类”,然后更改 XCode 代码超类回到 UIControl。 IB 接受并更改了课程,但运行该应用程序给了我不可见的按钮。 IB 属性检查器仍然将其显示为按钮。
从头开始创建控件并重新布线是可行的,但我希望如果可以避免的话,不要重新布线所有按钮。 (这是我希望跨多个应用程序进行的更改,因此听起来有点痛苦)
有人知道解决这个问题的方法吗?
非常感谢!
I have a UIView filled with buttons that are all nicely hooked up to actions and outlets. However, in my infinite wisdom, I decided that I really would rather have the button behavior to be different and subclassed a UIControl.
My plan was to hop into Interface Builder, change the class of the buttons to my new UIControl subclass, and then be up and running. This would preserve all of outlet and action connections.
In IB (View Identity Inspector) when I type in my UIControl subclass into the class field, it reverts back to UIButton when I tab out. Any UIButton subclass works, but not a UIControl. I can go down the inheritance tree but not up....
The first plan was to go to XCode and change the superclass of my new control temporarily to UIButton, change the 'class' of my IB buttons, and then change the XCode code superclass back to UIControl. IB accepted and changed the class, but running the app gives me non-visible buttons. The IB Attributes inspector still shows it as a button.
Creating the control from scratch and rewiring works, but I was hoping to not rewire all the buttons if it could be avoided. (This is a change I was hoping to roll across multiple apps, so it is a bit more painful that it sounds)
Anyone know any way around this?
many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这方面晚了一年,但也许它会对未来的某人有所帮助。也许您可以在文本编辑器中打开 .xib 并找出需要更改哪些文本才能使其正常工作(首先在示例项目中尝试),然后使用查找和替换一次性修复所有这些问题。
I'm a year late on this, but maybe it will help someone in the future. Perhaps you could open the .xib in a text editor and figure out what text you would have to change to get it to work (try it on a sample project first), then use find and replace to fix all of them at once.