In xCode, I'm getting the error “Loaded the ni

2019-08-12 06:36发布

I know there are multiple questions asking the same thing, but none of their solutions worked for me.

I made a custom viewController class (Home), and I made a .xib separately. (Effectively, I'll have 2 nibs -- one for the ipad version to load, and another for the iphone).

When I try to instantiate an instance of the home class, I got the error I mentioned in the question.

In the xib file, all I did was drag a viewcontroller object from the library to the screen, and it automatically added a viewcontroller icon below the file's owner and the first responder. I then went into the inspector of the viewController object and changed the class from viewController to Home.

The next step that I've discerned from the solutions is to connect the view outlet from the inspector. I'm not entirely sure what I'm supposed to be connecting it to. The solutions I've found say to connect it to the view icon, but again, all I see is files owner, first responder, and the vc object. It connects to none of them

Here is what I put in the app delegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

 Home *homePage = [[Home alloc] initWithNibName:@"HomeIpad" bundle:nil]; 

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:homePage];
[self.window addSubview:navController.view];
[self.window makeKeyAndVisible];
return YES;
}

3条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-12 07:26

I would suggest you to create the Nib using Xcode's File->New->New File->Cocoa Touch->UIViewController subclass->with XIB for user interface (do this twice, once with Targeted for iPad checked). I find this to be the most reliable way of creating and hooking up XIBs.

Even if you want two XIBs for the same controller, create the 2nd VC subclass using any temporary name (say tempvc). Now, rename tempvc.xib to HomeIpad.xib. Right Click on HomeIpad.xib and select Open As->Source code. In the source, search for tempvc and replace it with the name of your controller for all occurrences. Everything should be good now.

查看更多
看我几分像从前
3楼-- · 2019-08-12 07:27

the problem was that for the file's owner, i hadn't set the class to Home

查看更多
走好不送
4楼-- · 2019-08-12 07:34

You dont need to drag the view controller. Just drag a UIView instead and connect the File's owner View to this UIView.

查看更多
登录 后发表回答