1

I'm working on app that allows user to share photo like instagram. User can post a photo with or without caption, so the caption could be empty and the photo still posted to their feed. My client want to remove the view when the caption is empty and I'm using uitableview cell with autolayout for the post. When I tried to connect the captionview height constraint to my viewcontroller it gives me an error it says that the constraint outlet can't be connected to repeated content. So, I tried to do it inside my code , but it doesn't change anything.

let captionString = object["caption"] as? String
    let captionView = cell.contentView.viewWithTag(111)

    if captionString == ""{

        captionView?.frame = CGRectMake(0 , 0, captionView!.frame.width, 0)

    }else{


        (cell.contentView.viewWithTag(12) as! UILabel).text = captionString

    }

I put above code inside tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell and I'm giving constraint in every view inside uitableviewcell so if I can change the captionView height other view will automatically resizing. How can I change the height of the captionView?

Ega Setya Putra
  • 1,645
  • 6
  • 23
  • 51

2 Answers2

0

Related info here:

Outlets cannot be connected to repeating content iOS

You can't set the frame, when you're using autolayout that's invalid and won't work properly.

Either have 2 different styles of cell and choose which one to dequeue based on data availability, or add constraints so that you can collapse the label height to zero.

pkamb
  • 33,281
  • 23
  • 160
  • 191
Wain
  • 118,658
  • 15
  • 128
  • 151
0

you can create outlet of height constraint and set the height 0

like as:

@IBOutlet var captionViewHeightConstraint: NSLayoutConstraint!
captionViewHeightConstraint.constant = 0
pkamb
  • 33,281
  • 23
  • 160
  • 191