2010-09-09 37 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

相关问题