Loading xib crashes app

自作多情 提交于 2019-12-14 03:22:11

问题


Hello all I am having a issue with showing a xib file from the main file not sure why this is happening with some of the xib files and not others.

if(segment == @"1"){
    Results1 *myView1 = [[Results1 alloc]initWithNibName:@"Results1" bundle:nil];
    [self.view addSubview:myView1.view];
}else if(segment == @"2"){
    Results2 *myView2 = [[Results2 alloc]initWithNibName:@"Results2" bundle:nil];
    [self.view addSubview:myView2.view];
}else if(segment ==@"3"){
    Results3 *myView3 = [[Results3 alloc]initWithNibName:@"Results3" bundle:nil];
    [self.view addSubview:myView3.view];
}else if(segment ==@"4"){
    Results4 *myView4 = [[Results4 alloc]initWithNibName:@"Results4" bundle:nil];
    [self.view addSubview:myView4.view];
}

Is my code the first xib files opens but not the rest I am not sure why, I have added .h files:

#import "Results1.h"
#import "Results2.h"
#import "Results3.h"
#import "Results4.h"

the app ends up on this line when debugging:

@autoreleasepool {
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([TestTypingToolAppDelegate class]));
}

and then it crashes, anyone have any idea?


回答1:


Tim, here is a picture from the Interface Builder, maybe it helps you:




回答2:


You need to look at the console output when the application takes you to that line in your main.m. For me it was always a mistake on my part with the most common mistake being 1) The file does not exist (Results1.xib) or 2) I forgot to set the view outlet. As I mentioned the details from the exception in console output will help you.




回答3:


Keep in mind that sometimes loading a view crashes on the device but not the simulator. In this situation, check to ensure that when you call:

 initWithNibName:@"YourNibName";

that the casing of your nib name string is exactly the same as the nib file. The simulator ignores cases, but the device requires an exact match (pretty irritating)



来源:https://stackoverflow.com/questions/11906618/loading-xib-crashes-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!