简体   繁体   中英

loading a xib file

Hello I am just a beginner.

I have created a new xib file. Now I am trying to call it like the code below but it does not work.

This is what I have done in file's owner:

在此处输入图片说明

UIViewController *controller;
controller = [[UIViewController alloc]initWithNibName:@"UserFeedback" bundle:nil];
[self.view addSubview:controller.view];

The error that I am getting is:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "UserFeedback" nib but the view outlet was not set.'

I hope, you have created "controller.h" and "controller.m" UIViewController.

Then give the class "controller" into "UserFeedback" .xib file.

And bind the view object with "UserFeedback" .xib file.

Try with this and let me know.

Almost you will get success.

Cheers!

Here is the technique you can use:

UIViewController *controller; controller = [[UIViewController alloc]initWithNibName:@"UserFeedback" bundle:nil]; [self.view addSubview:controller.view];

the above code is correct but first u have check controller view is binding or not ..i think error is say that your not binding controller view

Following diagram will help you understand

在此处输入图片说明 .

As I can see from your code Now

 ATMoviePlayerController *controller;
 controller = [[ATMoviePlayerController alloc]initWithNibName:@"UserFeedback" bundle:nil];
 [self.view addSubview:controller.view];

Seems the outlet is set correctly in the storyboard but while accessing it in the code you might have to ammend some code.

AFMoviePlayerController *controller = [[AFMoviePlayerController alloc]initWithNibName:@"UserFeedback" bundle:nil];
[self.view addSubview:controller.view];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM