出于某种原因,我无法让我的 base 64 编码图像显示在 aUIImageView
中UICollectionView
。
这是我的代码:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = @"task_cell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
NSDictionary* json = [dataSource objectAtIndex:indexPath.row];
[cell setBackgroundColor:[UIColor whiteColor]];
UIImageView *image = (UIImageView *)[cell viewWithTag:100];
UILabel *text = (UILabel *)[cell viewWithTag:101];
NSString *ext = [[json objectForKey:@"image"] pathExtension];
NSString *final = [NSString stringWithFormat:@"data:image/%@;base64,%@", ext, [json objectForKey:@"b64img"]];
NSURL *url = [NSURL URLWithString:final];
NSData *imageData = [NSData dataWithContentsOfURL:url];
[image setImage:[UIImage imageWithData:imageData]];
text.text = [json objectForKey:@"title"];
return cell;
}
调试日志:
Printing description of final:
data:image/jpg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/......(goes on for a while)
url = nil
imageData is nil
我确实看到了UILabel
变化。
那么,我应该尝试什么。