1

i am trying to make self sizing table view. the table view cell before editing is like this

enter image description here

there are 2 type of post in this table view cells. a post without image, and a post with an image. I want to make that second post 'Testting' which is only contains a text to shrink up using self sizing table view. I use this line of code in the viewDidLoad

  // to set the dynamic height of table view
    tableView.estimatedRowHeight = 100
    tableView.rowHeight = UITableViewAutomaticDimension

but the result it seems ugly. I think have used the right auto layout constraint before implementing self sizing table view. but i don't know what went wrong in here. it seems that it follows/depends the height of the image even though the image is not there

enter image description here

the autolayout contraints I used is like this enter image description here

username label constraints

enter image description here

avatar image constraints

enter image description here

post text label constraints

enter image description here

i suspect because it has 2 different constraint, one with image and the other doesn't have image. so how do i fix that ?

Alexa289
  • 8,089
  • 10
  • 74
  • 178
  • "I have used the right auto layout constraint before implementing self sizing table view" Obviously that's false. Remember, for this to work, the cell must size _itself_ using constraints from the inside out. However, you don't say anything about what your constraints _are_, so your question is pointless. – matt Dec 23 '17 at 02:42
  • "the table view cell before editing is like this " Nobody knows where your cell data comes from. – El Tomato Dec 23 '17 at 02:58
  • @matt sorry, I have added the constraints now. Thanks :) – Alexa289 Dec 23 '17 at 03:07
  • Do you have `heightForRowAt` implemented? Also, are you getting messages about your layout in the Xcode console?? If not, what happens when you use the View Debugger? Does it report any ambiguity issues? – matt Dec 23 '17 at 03:17
  • no i have not implemented heightForRowAt – Alexa289 Dec 23 '17 at 03:23
  • no i don't have any issue at all in debug area and also no layout issue :) – Alexa289 Dec 23 '17 at 03:50
  • Try this Give your post label to bottom constraints with Greater than equal , your imageview's bottom should be greater than equal relation. When you need to hide Image set height & Width Constraint to 0 – Prashant Tukadiya Dec 23 '17 at 05:13
  • @Alexa289 You should create two custom cell one with image and other one without image.Then you can set constraints individually in both cells – Vikky Dec 23 '17 at 05:24

0 Answers0