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:
- Create custom view files: File -> New -> File -> Objective-C Class and select type of UIView and name it MyView; MyView.h and MyView.m are created
- Create custom view nib: File -> New -> File -> User Interface -> View and name it 'cool'; cool.xib is created
- 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?
- Also, in IB, I highlight the File's Owner and set its Custom Class to MyView. (? - not sure about this)
- 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.
- I have a Single View Application and I would like to have an instance of MyView / cool on it so, in IB, I drag a View from the object inspector to the ViewController.xib view. In the IB Identity Inspector, I set the class to MyView. I import the MyView.h file into the ViewController.h and set up a property for it in the interface.
- In ViewController.m's viewDidLoad, I set the background color to orange and set the myLabel (which is being populated by Xcode so it seems to kinda work).
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