0 iphone xcode objective-c uiimage
我遇到了一个问题,即使在读完几个帖子后我也听不懂
这是我得到的错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0x576f8f0'
Run Code Online (Sandbox Code Playgroud)
这是代码:
- (void)viewDidLoad {
[super viewDidLoad];
NSString *filePath = [[self documentsPath] stringByAppendingPathComponent:@""];
NSFileManager *imagesFileManager = [NSFileManager defaultManager];
imagesArr = [[imagesFileManager contentsOfDirectoryAtPath:filePath error:nil]filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.jpg'"]];
arryList = [[NSMutableArray alloc] initWithArray:[imagesArr copy]];//display text
imagesList = [[NSMutableArray alloc]init];//display image
NSString *docPath = [self documentsPath];
for (NSString *anImagePath in arryList) {
anImagePath = [NSString stringWithFormat:@"%@/%@",docPath,anImagePath];
UIImage *image = [UIImage imageWithContentsOfFile:anImagePath];
if (image)
[imagesList addObject:image];
NSLog(@"%@", anImagePath);
}
}
Run Code Online (Sandbox Code Playgroud)
你不是那个呼唤lengtha的人UIImage,forin循环是.这是因为对象arrayList实际上是图像,但是循环认为它们是字符串,因为你基本上用这种方式对它们进行了类型化NSString *anImagePath.尝试更改您的代码:
for (NSString *anImagePath in arryList) {
anImagePath = [NSString stringWithFormat:@"%@/%@",docPath,anImagePath];
UIImage *image = [UIImage imageWithContentsOfFile:anImagePath];
if (image)
[imagesList addObject:image];
NSLog(@"%@", anImagePath);
}
Run Code Online (Sandbox Code Playgroud)
对此:
for (UIImage *image in arryList) {
if (image)
[imagesList addObject:image];
NSLog(@"%@", anImagePath);
}
Run Code Online (Sandbox Code Playgroud)
我猜你已经UIImage在数组中存储了对象.有关更多参考,请访问尝试显示图像数组,代码将iphone返回到主屏幕.
| 归档时间: |
|
| 查看次数: |
2510 次 |
| 最近记录: |