I know that there are several questions similar to this but I am finding that most of them don't work with current IB / iOS or are not complete.
I want to have a custom UIView that has a nib but am failing of getting this hooked up
properly. I have spent several hours debugging and off to SO I go (and maybe sit in bathtub). Apologies in advance if you feel that this is a simple operation; thx in advance for any help.
To do this currently, I:
I run the app and the backgroundColor is set to orange but no label and am cofused as to why not? Are any of the above steps incorrect?
thx in advance
In IB for cool.xib, go into Identity Inspector and set the Custom Class from UIView -> MyView; Question #1 - at this point does MyView know to load cool.xib when it is instantiated or does more need to be done?
It knows that your XIB is managed by that class. But more is needed to be done, in order for you to use that.
Skip the 4th question. That would work for a UIViewController
, where you define who is going to responsible for it, with the File's Owner.
I want to create a text label so I drag out a UILabel onto cool.xib and create a public property (myLabel) in MyView.h. Question #2 Do I need to set the custom class for this to MyView? I would think not as this is just a standard UILabel.
If you want to be able to access that UILabel from your MyView
, you should create an IBOutlet in your MyView
and link from the root UIView's (that is a sub-class of your MyView
) to the UILabel
. In this case, you don't touch the File's Owner.
Finally check this, in order for you load your custom view properly => Loading custom UIView from nib, all subviews contained in nib are nil?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.