DNB5brims
DNB5brims

Reputation: 30618

How to load a nib from a customized UIView?

I have a nib call "Hello.xib", and I have a HelloView that is inherit from the UIView, and I want to do the layout in the Hello.xib, and I want to allocate them to the HelloView.m / HelloView.h, how can I do so? Thank you.

Upvotes: 0

Views: 1048

Answers (3)

vikingosegundo
vikingosegundo

Reputation: 52237

Just today I wrote a demonstration code, that also uses instantiation of custom view by loading a nib

  • the controller has a member DetailContactHeaderView *headerView
  • in the nib, I have a DetailContactHeaderView and the Files' owner type is my Controller
  • the files' owner property headerView and the View get Connected
  • in this controller I have this code

    [[NSBundle mainBundle] loadNibNamed:@"DetailContactHeader" owner:self options:nil];
    

See my MyContacts for an implementation. FYI:

  • DetailContactHeaderView
  • DetailContactHeader.xib
  • DetailContactViewController
    • especially -tableView:viewForHeaderInSection:

Upvotes: 0

DarkDust
DarkDust

Reputation: 92384

You normally do so on the outside. In HelloView you should have a UIViewController derived class. Then when initializing it on the outside you would call:

hello = [[HelloViewController alloc] initWithNibName:@"Hello" bundle:nil];

The bundle:nil make Cocoa use the default bundle.

Upvotes: 2

Swapnil Luktuke
Swapnil Luktuke

Reputation: 10475

In the interface builder's inspector for your Hello.xib's view, set the class of the view (in identity tab) to HelloView. I hope thats what you are looking for.

Upvotes: 0

Related Questions