我有一个上载图像的网站,我正在尝试使用快速代码检索要在移动应用程序上显示的图像。查询数据库时,它仅返回图像名称(如下所示)。我无法显示正确的路径和图像。我是否要将image变量连接到文件夹的URL?我是否缺少我的PHP代码来获取信息?谢谢
查看手机文件
func setupThumbnailImage() {
let a = "http://url/regpaysubmit/uploads/"
let b = picture?.thumbnailImageName
let catUrl = a + b!
if let thumbnailImageUrl = picture?.thumbnailImageName{
thumbnailImageView.loadImages(urlString: thumbnailImageUrl)
}
print(catUrl)
}
let thumbnailImageView: UIImageView = {
let imageView = UIImageView()
imageView.image = UIImage(named: "insert info to display images????")
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
return imageView
}()
控制器文件
var pictures: [Picture]?
func fetchPictures() {
guard let url = NSURL(string: "http://url/testApp/service.php") else {return}
URLSession.shared.dataTask(with: url as URL) { (data, response, error) in
if error != nil {
print(error!)
return
}
do {
let json = try JSONSerialization.jsonObject(with: data!, options: .mutableContainers)
self.pictures = [Picture]()
for dictionary in json as! [(AnyObject)] {
let picture = Picture()
picture.title = dictionary["user_bizName"] as? String
picture.thumbnailImageName = dictionary["user_bizPic"] as? String
self.pictures?.append(picture)
}
DispatchQueue.main.async {
self.collectionView?.reloadData()
}
} catch let jsonError {
print(jsonError)
}
}.resume()
}
它是空白图像,但在底部控制台上显示的是带有图像的url地址文件: