在表视图中显示图像的 base64 字符串数组

array of base64 strings to image in tableview

我有一个数组,其中包含格式为 base 64 字符串的图像,我需要在 table 视图中绑定。我已尝试使用以下代码将 base 64 转换为图像代码

UIImage *image = [UIImage imageWithData:[NSData dataFromBase64String:result]];

但是我有数组。如何从 base 64 格式的数组中获取图像。任何代码都将 helpful.Kindly 在 swift

中提供

这样试试:

- (UIImage *)decodeBase64ToImage:(NSString *)strEncodeData {
  NSData *data = [[NSData alloc]initWithBase64EncodedString:strEncodeData options:NSDataBase64DecodingIgnoreUnknownCharacters];
  return [UIImage imageWithData:data];
}

然后在您的表格视图单元格中,像这样调用:

cell.imageView.image = [self decodeBase64ToImage:result[indexPath.row]];;

Swift 3.0

func decodeBase64image(toImage strEncodeData: String) -> UIImage {
var data = Data(base64Encoded: strEncodeData, options:.ignoreUnknownCharacters)
return UIImage(data: data)!
}

然后

cell.imageView?.image = decodeBase64image(toImage: result[indexPath.row])