views:

145

answers:

1

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?

+2  A: 

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];
Brad Smith
Sorry to sound dumb, but where would I put this: [MyRidesListView alloc] initWithNibNAmed:@"MyRidesListView" bundle:nil]; ? Also, are you saying to not use the -(id)initWithNibName method?
Nic Hubbard
there where you want to show it. if it is the first view, init it in your app delegate
choise
@Nic: don't take this the wrong way, but you are missing a fundamental point. The first of Brad's code fragments is the *definition* of the method initWithNibNamed:bundle:. The second is an invocation of that method (there's two typos in it, as it happens). Any time you want to create a new object of type MyRidesList view, you use `[[MyRidesListView alloc] initWithNibNamed:@"MyRidesListView" bundle:nil];` The first fragment beginning `- (id)initWithNibName:(NSString *)nibNameOrNull bundle:bundle...` determines what happens when the method is invoked.
JeremyP
JeremyP is correct, and I edited the two small typos he mentioned.
Brad Smith