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

Xino

macrumors member
Original poster
Sep 5, 2008
36
0
I'm trying to load an UIView from a NIB/XIB file.

The file is called 'Views.xib' and only contains a UIView (I didn't give it class name or something).

In the UIViewController class called 'viewController.m' I use the following code to bind the view of the UIViewController to the UIView within the XIB file.

Code:
NSArray* nibViews =  [[NSBundle mainBundle] loadNibNamed:@"Views" owner:self options:nil];
infoView = [nibViews objectAtIndex:0];
[self.view addSubview:infoView];

The application compiles without errors and/or warnings but the screen stays black... what am I doing wrong?

Thanks for your help :)
 

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
loadNibNamed returns a boolean, not an array. Also AFAIK it only takes one argument. Clean and see what warnings you get.
 

dejo

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
No, according to the Developer Documentation, NSBundle's "loadNibNamed: owner: options:" does return an array.

Return Value
An array containing the top-level objects in the nib file. The array does not contain references to the File’s Owner or any proxy objects; it contains only those objects that were instantiated when the nib file was unarchived. You should retain either the returned array or the objects it contains manually to prevent the nib file objects from being released prematurely.
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
FWIW, I tried this last night. It worked fine. I created a view nib with a label in it...

Where exactly did you place the above code? Are you sure its getting called? In my test, I simply put some code in the application delegate applicationDidFinishLaunching: method.

Seems an outlet is a better idea :eek:
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.