views:

57

answers:

2

Hi everyone; I am trying to find my way into Obj-C (iPhone) following this tutorial. Unfortunately there must be something missing in the code because the view of SubViewOneController does not appear.

Someone proposed a fix to this in the comments:

"The solution to the SubViewOneController’s view not appearing is that you need to tell the controller that the view will be initialized from a nib file. Go into SubViewOneController.m and un-comment the code starting with :

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {

change:

[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]

to:

[super initWithNibName:@"SubViewOne" bundle:nil]

then it should load the associated view object from the nib file of that name."

Unfortunately there are no such expressions in the code. He must have been referring to the snippets of code that were automatically generated by xCode that i dont have avalaible anymore. Could you please tell me with a short explanation what exactly to change now?

Thanks a lot in advance!

benny

A: 

try copying this into your SubViewOneController.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:@"SubViewOne" bundle:nil]) {
      // Custom initialization
    }
    return self;
}
gabtub
thanks a lot! this works for me
benny
A: 

I don't know if I would override initWithNibName. Why not just call initWithNibName when you need that view? For example, in the following code, I am getting a new view

-(void) GetHighScoresView { if (highScoresTableViewController == nil) { HighScoresViewController *aView = [[HighScoresViewController alloc] initWithNibName:@"HighScoresView" bundle:[NSBundle mainBundle]]; self.highScoresViewController = aView; [aView release]; } }

mahboudz