-1

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?

Tim
  • 115
  • 1
  • 2
  • 10
  • what are the names of the `xib` files? what kind of objects are the _Results_? has the `view` been connected to the `view` property in each view controller? many, many things are not clear to find out the reason of the crash. – holex Aug 10 '12 at 17:42
  • 1
    It may not help in this case but using `==` for string comparison is inherently wrong unless you're interested in the address of the objects. Switch to `isEqualToString:`. – Phillip Mills Aug 10 '12 at 17:47
  • Not sure how to connect the view? But the first one works and they are all the same so I assumed they all should work, when I walk threw the code it does see what xib it should load it just does not load. – Tim Aug 10 '12 at 17:54
  • @Tim, you should connect them manually. have you done it yet? – holex Aug 10 '12 at 17:57

3 Answers3

0

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.

Joe
  • 56,979
  • 9
  • 128
  • 135
0

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

enter image description here

holex
  • 23,961
  • 7
  • 62
  • 76
0

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)

lohiaguitar91
  • 522
  • 5
  • 9