1

我很确定这是一个简单的解决方法,但它太具体了,我不知道在哪里可以找到答案……我想创建一个方法,从执行它的对象中检索和使用 UIImage。

这是调用以 imageView 作为对象的方法的行。

[self performSelector:@selector(method:) withObject:self.imageView afterDelay:0.0];

这就是方法...

- (void) method:(UIImage *) image {

if ([image isEqual:image1]){
    x = 1;
}
if ([image isEqual:image2]){
    x = 2;
}
if ([image isEqual:image3]){
    x = 3;
}
if ([image isEqual:image4]){
    x = 4;
}
if ([image isEqual:image5]){
    x = 5;
}

...我是否以正确的方式解决这个问题?谢谢!

4

2 回答 2

0

使用此方法

[self performSelector:@selector(method:) withObject:self.imageView.view afterDelay:0.0];

UIImageview作为参数而不是传递UIImage

于 2013-02-15T09:26:52.187 回答
0

要从 UIImageView 对象中检索 UIImage 你应该使用

[self.imageView image];

如果你想创建一个方法,从执行它的对象中检索和使用 UIImage。(我猜你正在使用 UIImageView 对象......)你应该继承或添加类别到 UIImageView 并向它添加这样的方法

- (void) method {
   UIImage* image = [self image];
   //do whatever you want with the image
   //...
}

作为替代方案,您可以将 UIImageView 传递给该方法并让它检索图像,然后将其用于任何目的

- (void) method:(UIImageView*)imageView {
   UIImage* image = [imageView image];
   //do whatever you want with the image
   //...
}
于 2013-02-15T09:28:23.813 回答