【问题标题】:existing instance variable delegate for property delegate with assign attribute must be unsafe_unretained具有 assign 属性的属性委托的现有实例变量委托必须是 unsafe_unretained
【发布时间】:2013-03-08 15:26:21
【问题描述】:

出现错误

@protocol TapDetectingImageViewDelegate;

@interface TapDetectingImageView : UIImageView {
id <TapDetectingImageViewDelegate> tapDelegate;

@property (nonatomic, assign) id <TapDetectingImageViewDelegate> tapDelegate;

@synthesize tapDelegate;

什么都试过了

 _weak id <TapDetectingImageViewDelegate> tapDelegate;

 @property (weak) id <TapDetectingImageViewDelegate> tapDelegate;

甚至也试过了

_unsafe_unretained id <TapDetectingImageViewDelegate> tapDelegate;

@property (_unsafe_unretained) id <TapDetectingImageViewDelegate> tapDelegate;

甚至尝试删除实例变量定义,因为在使用 ARC 模式时,综合会处理它。

但仍然无法消除此错误。

如果有人可以帮我解决这个错误。

谢谢。

【问题讨论】:

  • 这是__weak,而不是_weak
  • 我改了,但还是报错
  • 我不得不清理它然后再次分析它,现在错误消失了。非常感谢你。我为此快疯了。
  • 这个版本你试过了吗:@property (weak) id tapDelegate;除了消除 ivar 和 @synthesize?这是标准方式,应该可以工作(可能也应该在声明中添加非原子)。
  • 不要继承 UIImageView 来做到这一点。使用 UIGestureRecognizer。组合优于继承...

标签: iphone objective-c automatic-ref-counting xcode4.5


【解决方案1】:

我是 Obj-C 的新手,我找到了这个解决方案 https://stackoverflow.com/a/10080387/3867557 你的代码应该是这样的:

@protocol TapDetectingImageViewDelegate;
@interface TapDetectingImageView : UIImageView 
@property (nonatomic, assign) id <TapDetectingImageViewDelegate> tapDelegate;

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多