I have a UIViewController class MyClass that initially had no XIB, and was initialized programmatically. Now, I don’t want to load it from an XIB, but I do want to make a small 50×50 UIView (settings overlay view), and I want to add it MyClass, so instead of programatically declaring the new settings overlay view, I thought I would create an XIB file, set the file’s owner to MyClass, declare in MyClass.h an IBOutlet UIView *settingsOverlay, and link it in the XIB.
Then in the viewDidLoad method, I do [self.view addSubview:settingsOverlay], but for some annoying reason it doesn’t work. It just doesn’t appear. I tried creating a simple UIImageView programmatically and adding it to the subView, and it works just fine, but when done through the XIB, it doesn’t work. Can anyone point out what could possible be wrong? Please let me know what other details I might need to include.
If you are trying to add a view using xib then you need to use loadNibNamed method.
You can refer developer link for more info – http://developer.apple.com/library/IOs/#documentation/UIKit/Reference/NSBundle_UIKitAdditions/Introduction/Introduction.html