XCode Interface Builder: Change class of already p

2019-04-18 16:44发布

问题:

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

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

回答1:

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.

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.

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



回答2:

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