我有这样的代码
arrayWithImages = [[NSMutableArray alloc] init];
NSEnumerator *enumForNames = [arrayWithNames objectEnumerator];
NSEnumerator *enumForURLs = [arrayWithURLs objectEnumerator];
id objName, objURL;
while(objName = [enumForNames nextObject]) {
objURL = [enumForURLs nextObject];
UIImageView *anImage = nil;
[anImage setImageWithURL:[NSURL URLWithString:objURL]];
(...)
[arrayWithImages addObject:anImage];
}每次我让SIGABRT与"arrayWithImages addObject:anImage;“保持一致,这里出了什么问题?
发布于 2012-03-28 07:46:59
我在UIImageView上看不到setImageWithURL方法。这是从哪里来的?
SIGABRT崩溃是否有任何输出?
尝试以下代码:
// Download the image
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:objURL]];
// Make an UIImage out of it
UIImage *anImage = [UIImage imageWithData:imageData];
// Create an image view with the image
UIImageView *imageView = [[UIImageView alloc] initWithImage:anImage];
// Check to make sure it exists
if (imageView != nil) {
// Add it to your array
[arrayWithImages addObject:imageView];
else {
NSLog(@"Image view is nil");
}请注意,您应该异步下载图像,以避免挂起循环。This blog post讨论异步镜像下载。
此外,如果您知道[enumForURLs nextObject];将返回一个NSString (或者更好的,NSURL),那么您应该将objURL赋给类型NSString (或NSURL)。
https://stackoverflow.com/questions/9899209
复制相似问题