【问题标题】:Incompatible pointer types sending 'UITapGestureRecognizer *' to parameter of type 'UIView * _Nonnull'不兼容的指针类型将“UITapGestureRecognizer *”发送到“UIView * _Nonnull”类型的参数
【发布时间】:2015-10-23 08:27:45
【问题描述】:
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureAction)];
tapGestureRecognizer.numberOfTapsRequired = 1;

self.fullScreenImageView = [[UIImageView alloc]initWithFrame:self.frame];
self.fullScreenImageView.image = [UIImage imageNamed:@"family"];
self.fullScreenImageView.userInteractionEnabled = YES;
[self addSubview:self.fullScreenImageView];
[self.fullScreenImageView addSubview:tapGestureRecognizer];

这些代码有什么问题。
Xcode 7.0 给出了这个错误:

不兼容的指针类型发送“UITapGestureRecognizer *”到 'UIView * _Nonnull' 类型的参数

【问题讨论】:

    标签: ios objective-c iphone xcode7


    【解决方案1】:

    您应该使用 addGestureRecognizer 向 UI 对象添加手势

    // [self.fullScreenImageView addSubview:tapGestureRecognizer];
    
    [self.fullScreenImageView addGestureRecognizer: tapGestureRecognizer];
    

    【讨论】:

    • 如果您使用像我的答案这样的解决方案,请标记为正确。或者请发布您的解决方案。
    • UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureAction)]; tapGestureRecognizer.numberOfTapsRequired = 1; [self addGestureRecognizer:tapGestureRecognizer]; self.fullScreenImageView = [[UIImageView alloc]initWithFrame:self.frame]; self.fullScreenImageView.image = [UIImage imageNamed:@"family"]; self.fullScreenImageView.userInteractionEnabled = YES; [自我 addSubview:self.fullScreenImageView];喜欢你的
    【解决方案2】:
        UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestureAction)];
        tapGestureRecognizer.numberOfTapsRequired = 1;
        [self addGestureRecognizer:tapGestureRecognizer];
    
        self.fullScreenImageView = [[UIImageView alloc]initWithFrame:self.frame];
        self.fullScreenImageView.image = [UIImage imageNamed:@"family"];
        self.fullScreenImageView.userInteractionEnabled = YES;
        [self addSubview:self.fullScreenImageView];
    

    这就是解决方案。我找到了谢谢@anhtu

    【讨论】:

    • 当有人回答您的问题时,如果您发现该回答有帮助,您应该通过单击该回答附近的绿色票来接受该回答。您不应该创建新答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多