4

I'm trying autolayout with textview and it works perfectly fine when the view is loaded but when I go to another viewcontroller and come back to this viewcontroller what I see is all the autolayout is lost, here are the screenshots.

This is what it looks like when the application is loaded:

normal layout

and when I go to other viewcontrollers (say 36 Blogs or Settings) and come back to Blog Posts I see that all the autolayouts are lost. Here's the screenshot of lost autolayouts:

broken layout

And this is console output when coming back to this view controller:

warnings

I'm using storyboard.

Filip Radelic
  • 26,607
  • 8
  • 71
  • 97
Ankit
  • 280
  • 2
  • 17
  • I wouldn't say AutoLayout has been completely disabled. But yes, the descriptions of the blog post are no more there and the thumbnails are slightly misplaced. – Cesare Feb 15 '15 at 11:02
  • yea its happening in all tableViews , in one tableview i had 320x100 blog post thumbnail image under TextView , that image disappears as well. Trying to figure out this from 2 days. – Ankit Feb 15 '15 at 11:06
  • Are you adding this constraints programmatically? – Ashraf Tawfeeq Feb 15 '15 at 11:20
  • nope using storyboard – Ankit Feb 15 '15 at 11:22
  • Are there any logs in the console when you leave or comeback? – gabbler Feb 15 '15 at 12:25
  • yes **unable to simultaneously satisfy constraints** http://i.imgur.com/I33Za56.png same error for all views and each and every cell – Ankit Feb 15 '15 at 12:35
  • 1
    Try to set an estimatedRowHeight for your tableview in viewWillDisappear, the rowHeight should be your average cell height. – gabbler Feb 15 '15 at 12:54
  • @gabbler that worked, although i used some random number instead of average height :) and it works even in viewWillAppear – Ankit Feb 15 '15 at 13:34
  • Yes, it doesn't have to be accurate, the 43.5 in your picture is an indication that the cell has collapsed to its default height. – gabbler Feb 15 '15 at 13:38
  • 1
    i actually tried estimatedRowHeight before but in viewDidLoad, well anyways finally it worked – Ankit Feb 15 '15 at 13:45
  • @gabbler I just noticed, it doesn't work in ios7, any solution for that? – Ankit Feb 19 '15 at 07:32
  • That's because self sizing cells is firstly introduced in iOS 8. For iOS7, implement heightforrow method. – gabbler Feb 19 '15 at 07:45
  • yes but How do i calculate heightforrow? and How do i make it this way, that heightforrowAtIndexPath function runs only in iOS 7xx, I can find the version of the phone and run this code " if version >= 8.0 { estimatedRowHeight } else run heightforrowAtIndexPath function. But I cannot call that function because its delegate, so this is where I'm stuck – Ankit Feb 19 '15 at 08:38

1 Answers1

1

I have tried creating issue you are facing. Here's what i did and try doing so what i did just set height of custom cell as I've done in the images below.

Here i've not set "heightForRowAtIndexPath:(NSIndexPath *)indexPath" programmatically. enter image description here enter image description here enter image description here enter image description here
Layout Constraints
enter image description here

Result :
enter image description here enter image description here enter image description here

Hope this solves your problem. If this still not solve your problem then pl. add screenshot of how you have set constraints to custom cell.

Dhaivat Vyas
  • 2,926
  • 1
  • 16
  • 26
  • problem was solved using estimatedRowHeight in viewWillDisappear. and in your cell it looks like you have set the height of textView to 42 may be thats why you got no issue, mine has top, left, right and bottom constrains because i wanted textView height to be dependent on text's length – Ankit Feb 15 '15 at 15:30
  • 1
    Ok thanks for the reply. It's good know that your issue is solved. – Dhaivat Vyas Feb 15 '15 at 15:45
  • I'also checked in my demo by removing textView height well it is working fine without breaking constraints as i've set row height to 100. But you can set - self.tableView.rowHeight = UITableViewAutomaticDimension; You can check it out it might get helpful to you in ur current issue or for setting dynamic tableView.rowHeight. Happy Coding. – Dhaivat Vyas Feb 15 '15 at 16:15
  • yes i tried that yesterday, didn't work and then i asked here – Ankit Feb 15 '15 at 16:23