如何将选择器声明为属性iOS以及如何使用我的属性?

时间:2012-01-26 15:24:22

标签: iphone ios ipad uiimageview uicontrol

我接下来写。所有代码都用ARC写的

@interface MPEvent : UIImageView
@property (nonatomic, unsafe_unretained) SEL action;
@property (nonatomic, strong) id target;

@end

选择器是否以正确方式声明?

在实现中,我接下来使用我的属性:

- (void)sendActionToTargetFromView:(id)view {
    [target performSelector:action withObject:view];
}

但编译器向我显示警告 警告:语义问题:PerformSelector可能导致泄漏,因为其选择器未知

如何修复此警告?

1 个答案:

答案 0 :(得分:5)

在下面的示例中,-Warc-performSelector-leaks仅针对一行代码被忽略,之后诊断将返回到先前存在的任何状态。

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [self.ticketTarget performSelector: self.ticketAction withObject: self];
#pragma clang diagnostic pop

pragma warnings help
Detailed description