Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

harry65

macrumors member
Original poster
Aug 26, 2008
36
0
Hi All -

I was wondering if there is any way to create a UIView from a XIB file? I'd like to set up my UIView in IB and then do something like:

Code:
UIView *myView = [[UIView alloc] initWithNibName:@"myNib.xib" bundle:nil];

I know UIViewController has the above method, but it does not look like UIView has this method. Is there no way to create a UIView from a XIB file? Am I trying to do something here that shouldn't/can't be done?

If this is not the correct way, any suggestions?

Thanks.
 
Why not use a UIViewController that actually has the code to load/initialise an xib file (not a trivial matter) and then use the view property to get the view?
 
I think what you are looking for is:

Code:
UIView *myView = [[[NSBundle mainBundle] loadNibNamed:@"myNib" owner:self options:nil] objectAtIndex:0];
 
I think what you are looking for is:

Code:
UIView *myView = [[[NSBundle mainBundle] loadNibNamed:@"myNib" owner:self options:nil] objectAtIndex:0];

Thanks!! I finally got this to work (I had some other issues with what I was trying to do). This is exactly what I was looking for.

@robbieduncan - I think that would have worked, though when I tried it I ran into the other problems that I had - I did not get to the point where a view would have showed up anyhow.

Thanks for the feedback!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.