Newbee
Newbee

Reputation: 3301

What are the possibilities of getting NULL IBOutlets while loading a view.. IOS

I have been working on IOS application. Before I had single project in which all source code was there application loaded properly in that setup, now I had split that into multiple projects. After that I am facing now a problem... in ViewDidLoad, IBOutlet for buttons all are coming nil values, view also loading black colored. I am not able to guess what was the problem. Any idea about what could cause this...

I have loaded my view like this...

 main =[[main_page_controller alloc] init];

    if (main != NULL) 
        [root.navigationController pushViewController:main animated:YES];

I am not sure which part of the code do I need to post here, to make the question more understandable... Please share your suggestions..

Edit: I ran my old project and then tried with my new set up application launching successfully. I removed the application from device, and loaded using new set up only, problem again shows up. So what was there in old set up? What am I missing in new... ????

Upvotes: 0

Views: 795

Answers (2)

WDUK
WDUK

Reputation: 19030

Refer to the documentation

To initialize your view controller object using a nib, you use the initWithNibName:bundle: method to specify the nib file used by the view controller. Then, when the view controller needs to load its views, it automatically creates and configures the views using the information stored in the nib file.

When initialising a view controller, and you're using a .xib file for the view, you need to call initWithNibName:bundle:. This means it'll use the xib file to create the view within loadView. At the moment, you're just using init, that will create a blank UIViewController object.

So in this case, your code would be (assuming the .xib is called "MainViewControllerView.xib" within the main bundle):

main =[[main_page_controller alloc] initWithNibName:@"MainViewControllerView" bundle:nil];
if (main) {
    [root.navigationController pushViewController:main animated:YES];
}

Also sanity check your .xib file to see if all the IBOutlets are connected to what you want.

Upvotes: 1

Rajneesh071
Rajneesh071

Reputation: 31081

First check all your connection in xib(nib) file, if its already connected then just disconnect them , clean project (cmd+k) and then connect connection again.

take a look on this image for connection

enter image description here

Upvotes: 1

Related Questions