2010-09-09 39 views
0

我有這樣的代碼:我可以忽略這個iphone的警告嗎?

if([annotation respondsToSelector:@selector(tag)]){ 
    disclosureButton.tag = [annotation tag]; 
} 

,我得到警告:

' - 標籤' 在協議

很公平沒有找到,但我已經創建了一個新的對象與具有合成的int tag變量的協議。

編輯:發現爲什麼應用程序崩潰 - 不是這一行。現在我只是得到一個警告,應用程序工作正常。

感謝,是因爲對於靜態類型的annotationMKAnnotation產生 湯姆

+0

你試過啓用NSZombieEnabled? – willcodejavaforfood 2010-09-09 09:37:12

+0

你不認爲它的這一行?調試器對此有什麼要說的? – 2010-09-09 09:37:13

+0

EXC_BAD_ACCESS - 這是一個我沒有保留的變量......所以根本不是那條線。這條線只是給我一個警告。將看看NSZombieEnabled ...不知道它做了什麼。 :)謝謝 – 2010-09-09 09:39:47

回答

4

警告,有沒有方法-tag。由於您已經檢查過動態類型對選擇器做出響應,您可以忽略此情況下的警告。

爲了擺脫的警告:

  • 如果你希望某個類,你可以測試它,而不是:

    if ([annotation isKindOfClass:[TCPlaceMark class]]) { 
        disclosureButton.tag = [(TCPlaceMark *)annotation tag]; 
    } 
    
  • 對於一個協議:

    if ([annotation conformsToProtocol:@protocol(PlaceProtocol)]) { 
        disclosureButton.tag = [(id<PlaceProtocol>)annotation tag]; 
    } 
    
  • 或者如果兩者都不適用,則使用特定協議來抑制警告(例如,對於ra pidly改變蘋果的API):

    @protocol TaggedProtocol 
    - (int)tag; 
    @end 
    
    // ... 
    if([annotation respondsToSelector:@selector(tag)]){ 
        disclosureButton.tag = [(id<TaggedProtocol>)annotation tag]; 
    } 
    
+0

這太神奇了! :) 謝謝 – 2010-09-12 13:15:43

相關問題