Load XIB into View of another XIB

741 views Asked by At

I have an XIB file that has a CustomUserView (UIView with base class CustomUserView) that is blank and a UIButton. This has a controller, MyMainController. In the main controller method I have the code:

//Set up user info view
        customUserView  = (NSBundle.mainBundle().loadNibNamed("CustomUserViewXIB", owner:nil, options:nil) as NSArray)[0] as CustomUserView

I have tried this code in both the viewDidLoad and viewWillAppear methods. Now the CustomUserViewXIB has some fields in it, that I would like to appear. However, I am only getting that blank CustomUserView and the button. Is there a way to do what I am trying to do, or will I have to add the CustomUserView as a subview?

1

There are 1 answers

9
matt On BEST ANSWER

If you're going to load another CustomUserView and configure it, of course you have to add it as a subview. Otherwise it's just something sitting there in your code. A view that isn't added as a subview to some view that's actually in the interface is, well, not in the interface.