开发者

What is "Unexpected interface name" in objective c, iPhone development?

I was using a class, MapMultiController, which extends UIViewController, and is instantiated from inside my ListViewController, which also extends UIViewController, like so:

@interface MapMultiController : UIViewController <UINavigationControllerDelegate, UINavigationBarDelegate> {
    MKMapView           *mapView;
    UISegmentedControl  *barStyleSegControl;
开发者_运维技巧    bool                wasUpdated;
}

and then this:

MapMultiController *controller = [[MapMultiController alloc] initWithNibName:@"MapMultiController" bundle:nil];
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];

This all worked before, but then I commented out the allocation and all that from my ListViewController, and did some other things, and now when I'm trying to put it back in, it says "Unexpected interface name 'MapMultiController'", and of course everything after that doesn't work.

But everything looks correct to me! What's wrong?


What probably happened is that in the course of your editing, you added some code before that @interface and now the compiler isn't expecting it where it's finding it. It's not that your code is wrong, but that it's in the wrong place.


This error usually happens when you create an object where object creation is simply not allowed.

This very same error happened to me when I was allocating an object inside a switch statement:

switch (myInt) {
    case 1:
        NSString *string = @"Hello Exception!";
        break;
    default:
        break;
}

Yields following error:

Semantic Issue: Unexpected interface name 'NSString': expected expression


Shaharyar isn't strictly correct, you can alloc and create objects from within a switch statement as-long as you enclose each case with curly brackets.

The following is valid use of the switch statement:

switch (myInt) {
    case 1:
    {
        NSString *string = @"Hello Exception!";
        break;
    }
    default:
        break;
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜