嗨,我有一个项目,我实现了ImageSlideshow和sdwebimage。图像是通过API调用获得的,但在ImageSlideshow的文档中,SDwebImages的实现如下所示
let sdWebImageSource = [SDWebImageSource(urlString: "https://images.unsplash.com/photo-1432679963831-2dab49187847?w=1080")!, SDWebImageSource(urlString: "https://images.unsplash.com/photo-1447746249824-4be4e1b76d66?w=1080")!, SDWebImageSource(urlString: "https://images.unsplash.com/photo-1463595373836-6e0b0a8ee322?w=1080")!]
它工作得很好,但对于我自己的项目,我有一个数组中的所有图像,我想在ImageSlideshow中显示这些图像。我不知道图像的数量,所以很难对其进行硬编码,所以我如何传递图像数组。ProductServices.instance.selectedProduct?.productImg[0])
这给了我第一个索引处的图像。图像可以达到第五级索引。我怎么才能通过这个?
发布于 2018-06-02 08:24:24
你可以试试
var allImages = [SDWebImageSource]()
if let allStr = ProductServices.instance.selectedProduct?.productImg {
for str in allStr {
allImages.append(SDWebImageSource(urlString:str))
}
}
if allImages.isEmpty {
// display custom image // or add it's default str
}
https://stackoverflow.com/questions/50652391
复制相似问题