Nic Hubbard
Nic Hubbard

Reputation: 42139

iPhone: Error when using -(id)initWithNibName

I am trying to use the following code, but I always get an error that I can find little information about:

- (id)initWithNibName:@"MyRidesListView" bundle:nil {
    if ((self = [super initWithNibName:@"MyRidesListView" bundle:nil])) {
        // Custom initialization
    }
    return self;
}

Error:

expected identifier before 'OBJC_STRING' token

This seems like a simple method to be calling. This is for a UINavigationController.

Ideas?

Upvotes: 1

Views: 800

Answers (1)

Brad The App Guy
Brad The App Guy

Reputation: 16275

It looks like you are trying to implement a constructor method in a subclass of UIViewController or UINavigationController.

YOur syntax is a bit off. Without seeing what you are doing in a broader context I don't really know what is going on here, but this might help you out a bit. Its the closesest to your code while being syntactically correct.

- (id)initWithNibName:(NSString *)nibNameOrNull bundle:bundle {
    if ((self = [super initWithNibName:nibNameOrNull bundle: bundle])) {
        // Custom initialization
    }
    return self;
}

Then you can do this outside of your class:

[[MyRidesListView alloc] initWithNibNamed:@"MyRidesListView" bundle:nil];

Upvotes: 2

Related Questions