2011-09-10 121 views
1

我使用的是類,MapMultiController,它擴展的UIViewController,並從我的ListViewController,這也延伸的UIViewController,像這樣的內部實例:目標c,iPhone開發中的「Unexpected interface name」是什麼意思?

@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'「,當然之後的一切都不起作用。

但是一切對我來說都是正確的!怎麼了?

+0

是什麼MapMultiController.h其餘樣子(特別是位你的問題的代碼之前)? – deanWombourne

回答

4

可能發生的事情是,在編輯過程中,您在@interface之前添加了一些代碼,現在編譯器並不期待它找到它。這不是說你的代碼錯了,而是它錯了。

+0

謝謝,我找到了,而且你是對的。在我的情況下,我將if-else語句更改爲switch語句,並且語法錯誤。當我在箱子周圍加上大括號時,錯誤消失了。 – mutatron

3

當您創建一個對象創建對象時,通常會發生此錯誤不允許。發生在我身上

這非常相同的錯誤,當我被分配switch語句中的對象:以下錯誤

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

產量:

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

+0

謝謝,我找到了,你是對的。在我的情況下,我將if-else語句更改爲switch語句,並且語法錯誤。當我在箱子周圍加上大括號時,錯誤消失了。 – mutatron

+0

很高興聽到您的問題消失了。不要忘記接受幫助你的答案。 –

+0

您不需要切換到if-else語句。正如你所說,你可以在if-else和case結構中使用大括號。 –

2

沙哈里亞爾不完全正確,你可以ALLOC並在switch語句中創建對象,只要用括號括起每個case即可。

下有效使用switch語句:

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