Stranger B.
Stranger B.

Reputation: 9364

Dynamic layout in a UITableView Cell

I'm an Android developer, recently started to discover iOS using SWIFT 2

I would like to have a dynamic layout in my custom cell, I have an UImageView. and I have two cases :

  1. To show the image.

  2. To hide the image (OR to remove it) the Cell height should change

I've made my cell height dynamic using :

 tableView.rowHeight = UITableViewAutomaticDimension
        tableView.estimatedRowHeight = 160.0

How Can I achieve that ! here is my code :

 let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! PostCell

        if (posts[indexPath.row].PostImageURL == "None") {
            // Remove the Image
        } else {
            cell.PostImage.load(posts[indexPath.row].PostImageURL!)

        }

Upvotes: 0

Views: 49

Answers (1)

simnik
simnik

Reputation: 483

  1. You could try to set the UIImageView's Outlet to be hidden.
  2. You could try to set the UIImageView to nil
  3. You could try to loop through the sub idea of your Cell and remove the UIImageView from the View Hierarchy.

Hope I could help!

Upvotes: 1

Related Questions