我在自定义 UITableViewCell 中显示 UIImageView ,仅用于那些在 Firebase 响应中设置了图像 URL 的单元格。代码如下:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cellIdentfier = "ArticleTableViewCell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentfier, forIndexPath: indexPath) as!ArticleTableViewCell
//Configure the cell
// Added by ankit khanna for UIImageView change
let imageURL = imageArray[indexPath.row]
print ("Final Image URL: [\(imageURL)]")
if (imageURL == "NIL") {
cell.articalImageView.hidden = true
}
let fileUrl = NSURL(string: imageURL as String)
print ("File URL : [\(fileUrl!)]")
cell.articalImageView.hnk_setImageFromURL(fileUrl!)
// End
}
问题是如果我删除了 if 条件if (imageURL == "NIL")
图像显示正确,但是当我向上滚动图像开始显示它不应该显示的位置时。
图像阵列:var imageArray = [String]()
下面是我在其中附加数组的代码
if (snapshot.value.objectForKey("image") != nil)
{
let url = snapshot.value.objectForKey("image")!
let f_url = String(url)
// print ("image1 URL : \(f_url)")
self.imageArray.append(f_url)
}
else if (snapshot.value.objectForKey("image") == nil)
{
self.imageArray.append("NIL")
}
我如何为空的响应禁用 UIImageView。