【问题标题】:Unrecognized selector sent to instance when extending UIImageView扩展 UIImageView 时发送到实例的无法识别的选择器
【发布时间】:2012-09-17 06:57:12
【问题描述】:

我搜索了所有类似的问题,但找不到答案。我对此完全感到困惑......我有一个扩展 UIImageView 的类。所以这是我的 .h 文件:

@interface Paper : UIImageView {
@public
    CGFloat drag;
}

@property (nonatomic, assign) CGFloat drag;
@end

我在我的实现中正确地合成了drag

现在,在我的 ViewController 中,我创建并初始化一个 Paper 对象,如下所示:

NSString *tempPath = [[NSBundle mainBundle] pathForResource:@"picture" ofType:@"png"];
UIImage *tempImage = [[UIImage alloc] initWithContentsOfFile:tempPath];
Paper *tempPaper = [[UIImageView alloc] initWithImage: tempImage];

对象是正确创建的,我稍后可以将它显示为子视图和所有爵士乐,但是当我尝试在上面使用如下行之后立即更改我的自定义属性时:

tempPaper.drag = 1.0;

[tempPaper setDrag:1.0];

我收到[UIImageView setDrag:]: unrecognized selector sent to instance 错误。我已经尝试了我找到的每一种不同的方法,但它不允许我为 Paper 类设置我的自定义属性(非 UIImageView 属性)的值。我错过了什么?我在这上面花了 2 个小时,这让我发疯了,我看不出有什么问题。

我也尝试在 Paper 的 initWithImage 方法中初始化 drag,但它也不起作用。

【问题讨论】:

    标签: iphone ios ipad uiimageview selector


    【解决方案1】:
    Paper *tempPaper = [[Paper alloc] initWithImage: tempImage];
    

    【讨论】:

    • 你是我的英雄,这解决了它......我不敢相信我错过了。谢谢!
    • 是的,它迫使我等待 10 分钟才能接受它。
    【解决方案2】:

    创建 Paper 类的对象而不是 UIImageView。

    纸张 *tempPaper = [[纸张分配] initWithImage: tempImage];

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-25
      • 1970-01-01
      • 2019-08-28
      • 2012-07-24
      相关资源
      最近更新 更多