UIImage方法没有被调用

时间:2013-02-14 10:00:36

标签: iphone ios

我正在尝试在视图上操作UIImage对象。但是当我尝试在UIImage类上调用任何方法时,它会抛出异常

2013-02-14 15:24:42.301 Test[4685:19a03] -[UIImage scaleToSize:]: unrecognized selector sent to instance 0x94642c0 
2013-02-14 15:24:42.303 Test[4685:19a03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage scaleToSize:]: unrecognized selector sent to instance 0x94642c0'
*** First throw call stack:`
(0x1cc1012 0x1ae6e7e 0x1d4c4bd 0x1cb0bbc 0x1cb094e 0x47ee9 0x47bc0 0xb0f817 0xb0f882 0xb0fb2a 0xb26ef5 0xb26fdb 0xb27286 0xb27381 0xb27eab 0xb27fc9 0xb28055 0xc2d3ab 0xa7e92d 0x1afa6b0 0x5c3fc0 0x5b833c 0x5b8150 0x5360bc 0x537227 0x5378e2 0x1c89afe 0x1c89a3d 0x1c66f61 0x1c66e1b 0x39117e3 0x3911668 0xa2e65c 0x31fcd 0x29d5)
libc++abi.dylib: terminate called throwing an exception

这是我正在使用的代码:

 UIImage *test = [[UIImage alloc] init];
    test = [UIImage imageNamed:@"image0.jpg"];
    [test scaleToSize:CGSizeMake(40.0f, 40.0f)];

2 个答案:

答案 0 :(得分:0)

看看UIImage's class reference。你找不到你想要的方法。也许你忘了添加一个你正在使用的类别(例如):

#import "UIImage+Scale.h"

答案 1 :(得分:-1)

首先定义图像尺寸然后缩放它。

UIImage *test = [[UIImage alloc] init;
test = [UIImage imageNamed:@"image0.jpg"];
[test scaleToSize:CGSizeMake(40.0f, 40.0f)];

尝试这行代码。或者在UIImageView中使用此图像