扩展 UIImageView 时发送到实例的无法识别的选择器



我已经搜索了所有类似的问题,但我找不到答案。 我完全被这个难住了...我有一个扩展UIImageView的类。 所以这是我的 .h 文件:

@interface Paper : UIImageView {
@public
    CGFloat drag;
}
@property (nonatomic, assign) CGFloat drag;
@end

我在实现中正确地合成drag

现在,在我的视图控制器中,我创建并初始化一个 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,但它也不起作用。

Paper *tempPaper = [[Paper alloc] initWithImage: tempImage];

创建 UIImageView 的 Paper 类对象。

Paper

*tempPaper = [[Paper alloc] initWithImage: tempImage];

最新更新