我有一个网格视图,我需要显示String中的gridview图像,其中包含要显示的URL。 请检查我收到错误的代码
- (void)viewDidLoad
{
_imageDatas=[[NSMutableArray alloc]init];
_imageDatas=[DelegateClass magazine].mg_art_of_sleeping;
NSLog(@"string %@",_imageDatas);
for(int z=0;z< [_imageDatas count]; z++){
NSLog(@"url%@",[[_imageDatas objectAtIndex:z] _image_url]);
}
- (MMGridViewCell *)gridView:(MMGridView *)gridView cellAtIndex:(NSUInteger)index
{
MMGridViewDefaultCell *cell = [[MMGridViewDefaultCell alloc] initWithFrame:CGRectNull];
cell.textLabel.text = [NSString stringWithFormat:@"Cell %d", index];
cell.imageView.image =[UIImage imageNamed:[_imageDatas objectAtIndex:index]];
// cell.imageView.image crash the code
return cell;
}
cell.imageView.image使用错误
导致代码崩溃2013-03-22 16:25:59.141 Magazine[3890:17c03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[ArtOfSleeping pathExtension]: unrecognized selector sent to instance 0x887bb40'
*** First throw call stack:
(0x207c052 0x1ae6d0a 0x207dced 0x1fe2f00 0x1fe2ce2 0xd9c979 0xc716f9 0xd004014 0xc714bd 0xd004072 0x103f2d 0x1054c5 0xc951b3 0x66cc17 0x67f12d 0x59f15d 0x67efd2 0x66ccf1 0x673281 0x66cd17 0x676c5c 0x5fcfb9 0x5feea6 0x5fe580 0x20509ce 0x1fe7670 0x1fb34f6 0x1fb2db4 0x1fb2ccb 0x2318879 0x231893e 0xc56a9b 0x30b5 0x2fb5)
答案 0 :(得分:2)
UIImage* myImage = [UIImage imageWithData:
[NSData dataWithContentsOfURL:
[NSURL URLWithString:[imageArray objectAtIndex:index]]]];
cell.imageView.image = myImage;
希望对你有所帮助
答案 1 :(得分:0)
不要使用imageNamed方法而不是使用initWithContentsOfFile
答案 2 :(得分:0)
我认为这很有用:
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",[_imageDatas objectAtIndex:index]]];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [UIImage imageWithData:data];