出於某種原因,我無法將我的base 64編碼圖像顯示在UIImageView
的UICollectionView
中。UICollectionView中的UIImage不顯示
這裏是我的代碼:
-(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
變化。
那麼,我應該嘗試什麼。
我假設你檢查imageData不是零? – onnoweb
是的,這是出於某種原因。爲什麼? –
你確定'dataWithContentsOfURL'支持這個嗎? –