XCode Interface Builder:更改已放置对象的类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12644687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:41:25  来源:igfitidea点击:

XCode Interface Builder: Change class of already placed object

xcodeuiviewinterface-builder

提问by brigadir

Is there a way to do it? I want not only set Class Identitybut change designed class (so object properties should change).

有没有办法做到这一点?我不仅要设置Class Identity而且要更改设计的类(因此对象属性应该更改)。

The reason is that I placed UIViewand a lot of subviews. Now I want to change it to UITableViewCell. Maybe it can be done by 'hacking' xib file?

原因是我放置UIView了很多子视图。现在我想把它改成UITableViewCell. 也许它可以通过'hacking'xib文件来完成?

回答by lillialexis

Unfortunately, maddeningly, there is no way to do this in InterfaceBuilder (that I have found). Changing the Custom Class just adds a custom class to the UIView, as opposed to changing the UIView to the class that you want it to be (e.g., UITableViewCell), bringing along all of the properties that your desired view may have. You can see this in the storyboard's XML file.

不幸的是,令人抓狂的是,InterfaceBuilder 中没有办法做到这一点(我已经找到了)。更改自定义类只是将自定义类添加到 UIView,而不是将 UIView 更改为您想要的类(例如,UITableViewCell),从而带来您想要的视图可能具有的所有属性。您可以在故事板的 XML 文件中看到这一点。

You want, say, this:

你想要,说,这个:

<label text="Label" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" ... id="Flb-Qd-jpJ"> ... </label>

and not this:

而不是这个:

<view ... id="Flb-Qd-jpJ" customClass="UILabel"> ... </view>

but Xcode is only giving you the latter; it's updating the view's customClass attribute as opposed to updating the entire element.

但 Xcode 只给你后者;它正在更新视图的 customClass 属性,而不是更新整个元素。

If you want the prior, you can still get it, but you'd have to edit the xml file yourself, keeping the element's id the same. Here is a great blog article explaining this in more detail: http://codenetwaves.blogspot.com.br/2012/09/change-view-to-scrollview-in-xcode.html

如果你想要之前的,你仍然可以得到它,但你必须自己编辑 xml 文件,保持元素的 id 相同。这是一篇很棒的博客文章,更详细地解释了这一点:http: //codenetwaves.blogspot.com.br/2012/09/change-view-to-scrollview-in-xcode.html

回答by Jeff Stone

In interface builder you'll open the third tab and find Custom Class. There you can change the UIView to a UITableViewCell

在界面构建器中,您将打开第三个选项卡并找到自定义类。在那里您可以将 UIView 更改为 UITableViewCell