Greg Peckory
Greg Peckory

Reputation: 8058

Changing image displayed in UIImage Swift

My image exists in as tableView Cell so I am using the following code to make changes to it: (I am updating image from cache if there is any confusion below)

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    if let nimage = cell.viewWithTag(111){   // 111 is a UIImageView

        nimage.image = imageCache[urlString]

        // above error - nimage has no member named image

        nimage = imageCache[urlString]

        // above error - cannot assign to 'let' value 'UIImage'

    }

what do I do?

Upvotes: 1

Views: 232

Answers (1)

Özgür Ersil
Özgür Ersil

Reputation: 7013

Type casting is a must here

 if let nimage:UIImageView = cell.viewWithTag(111) as! UIImageView{   // 111 is a UIImageView
        nimage.image = imageCache[urlString]
 }

Upvotes: 2

Related Questions