什么是“意外的接口名称”?在 Objective C 中,iPhone 的开发?

发布于 2024-12-03 20:13:59 字数 850 浏览 0 评论 0原文

我使用的是 MapMultiController 类,它扩展了 UIViewController,并从 ListViewController 内部实例化,ListViewController 也扩展了 UIViewController,如下所示:

@interface MapMultiController : UIViewController <UINavigationControllerDelegate, UINavigationBarDelegate> {
    MKMapView           *mapView;
    UISegmentedControl  *barStyleSegControl;
    bool                wasUpdated;
}

然后是这样的:

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

这一切之前都有效,但后来我注释掉了分配以及 ListViewController 中的所有内容,并做了一些其他事情,现在当我尝试将其放回去时,它显示“意外的接口名称'MapMultiController'”,当然之后的一切都不起作用。

但对我来说一切看起来都是正确的!怎么了?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

饭团 2024-12-10 20:13:59

可能发生的情况是,在编辑过程中,您在 @interface 之前添加了一些代码,而现在编译器并不期望它出现在它找到它的地方。不是你的代码错了,而是你的代码放错了地方。

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.

伊面 2024-12-10 20:13:59

当您创建一个不允许创建对象的对象时,通常会发生此错误。

当我在 switch 语句中分配对象时,也发生了同样的错误:

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

产生以下错误:

语义问题:意外的接口名称“NSString”:预期的表达式

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

他夏了夏天 2024-12-10 20:13:59

Shaharyar 并不完全正确,您可以从 switch 语句中分配和创建对象,只要您用大括号将每个情况括起来。

以下是 switch 语句的有效用法:

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

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;
} 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文