I am displaying an UIImageView inside a custom UITableViewCell for only those cells that have image URL set in Firebase response. Code as below:
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
}
Issue is if i remove the if condition if (imageURL == "NIL")
image displays correctly but then when i scroll back up image starts to show up where it shouldn't show up.
Image Array : var imageArray = [String]()
Below is the code where I am appending the array
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")
}
How am I suppose to disable the UIImageView for the response where it is empty.