IBOutlet instances are (null) after loading from NIB

Posted by Zach on Stack Overflow See other posts from Stack Overflow or by Zach
Published on 2009-08-11T01:09:38Z Indexed on 2010/04/24 10:43 UTC
Read the original article Hit count: 272

Filed under:
|
|
|

I am working on an iPhone app and am getting (null) references to IBOutlet fields in my controller. I have a UIViewController subclass that is set as the File's Owner in my XIB. I have a set of UI elements that are wired into the controller. After loading from NIB and attempting to set properties on those UI elements, I find that they are (null). To clarify, some code:

ExpandSearchPageController.h:

@interface ExpandSearchPageController : UIViewController
{
  IBOutlet UITextView * completeMessageView;
}

-(void)checkTextField;

@property (nonatomic, retain) IBOutlet UITextView * completeMessageView;

ExpandSearchPageController.m:

@implementation ExpandSearchPageController

@synthesize completeMessageView;

-(void)checkTextField
{
  NSLog(@"text field: %@",completeMessageView);
}

ExpandSearchPageController is set as the File's Owner for ExpandSearchPage.xib. ExpandSearchPage.xib's UITextView is wired to the completeMessageView.

When I call

ExpandSearchPageController * searchExpanderPage = [[ExpandSearchPageController alloc] initWithNibName:@"ExpandSearchPage" bundle:[NSBundle mainBundle]];

[searchExpanderPage checkTextField];

the result is

"text field: (null)"

Sorry if this is a total newb question, but I guess I'm still a newb at iPhone programming!

Thanks in advance!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about SDK