【发布时间】:2017-07-09 17:26:40
【问题描述】:
我正在从 firebase 获取图像 URL,但是当尝试在桌子上显示时我看不到一个。代码如下。我正在从
将图像保存在 firebaseUIImagePickerController()
public override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
let cell = tableView.dequeueReusableCell(withIdentifier: "allUsers", for: indexPath) as! allUserCell
cell.textLabel?.text = allUserData[indexPath.row].name
cell.detailTextLabel?.text = allUserData[indexPath.row].email
if let image = allUserData[indexPath.row].image {
let url = NSURL(string: image)
let request = URLRequest(url:url! as URL)
URLSession.shared.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) in
if error != nil{
print(error as Any)
return
}
DispatchQueue.main.async {
if let image = UIImage(data: data!) {
print(image)
cell.imageView?.image = image
}
}
}).resume()
}
return cell
}
}
打印(图像)行给了我以下信息:
UIImage: 0x60800009b3f0>, {746, 498}
自定义单元类。
class allUserCell:UITableViewCell{
override init(style:UITableViewCellStyle,reuseIdentifier:String?) {
super.init(style:.subtitle,reuseIdentifier:reuseIdentifier)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
【问题讨论】:
-
尝试打印
cell.imageView,看看是否得到nil -
@Aaron 你的意思是 cell.imageView.image ?
-
您使用的是自定义
UITableViewCell而不是default样式UITableViewCell,因此您需要手动将UIImageView添加到单元格的contentView中。 -
@Aaron 不这么认为,但我会这样做。
标签: swift uitableview swift3