3

This should be pretty straight forward, but it appears I need to reach out and ask if others have encountered this...

I've got a project on xcode 6 that's targeting iOS 7+. I'm using a storyboard and autolayout. I've created a UIViewController, dropped on a UITableView, and on that UITableView I've dropped on 3 different prototype cells, each with varying height. Each proto cell has its own UITableViewCell class, with UIElement linked accordingly.

These proto cells are designed in the GUI editor of the storyboard, and each of them have a fixed height. The will never grow in height like this: Using Auto Layout in UITableView for dynamic cell layouts & variable row heights

The problem with all examples I keep finding is that they all use a single prototype cell, and vary the height based on the content (i.e. they're using a UITextView and sizing the cell height based on how much text in in the view).

Since my proto cells are already designed in the storyboard, and they will never exceed their design height with dynamic content, all I want to do is show them as they are designed, when they are added to the table.

I'm using a switch statement in the cellForRowAtindexPath to determine which UITableViewCell class to use based on indexPath.row.

I created some dummy data in an array and use it to build a table with 3 rows, to see each of the 3 types of cells being rendered in the table.

This all works perfectly on iOS8. On iOS7, however, all three of my cells visually end up piled on top of each other.

For grins, I then implemented a heightForRowAtIndexPath method, and simply use a switch to determine what indexPath.row I'm dealing with, and then return back the height of the prototype cell (from the dimensions shown in the storyboard designer). This was supposed to be a simple, hard-coded approach to see if heightForRowAtIndexPath was needed to solve the issue.

Again, works great on iOS 8, but on iOS7 all 3 cells are piled on top of each other.

I guess a basic question is: since I'm using storyboard-designed prototype cells, that have fixed sizes and constraints on all of the UIComponent within those proto cells, why doesn't this work on iOS 7?

I'm trying to avoid adding tons of code just make this work on iOS7.

Community
  • 1
  • 1
Adam
  • 589
  • 3
  • 8
  • 19
  • hmm...did you try to run the app in an iOS 7 devices/simulators of different sizes, with different settings of the crosshair alignment tool on storyboard? It maybe the culprit, that something is wrong with your alignment when sizes change. It could be that it is showing up correctly on iOS8 only because iOS8 is clever enough to correct those mistakes for you. I had similar issue previous. So, it's just my guess. Hope this helps. – minjiera Feb 27 '15 at 23:39
  • The UI components within each cell are laid out correctly. The issue is that the cells are stacked on top of each other. It looks like you took three different UIViews and set them to the same x/y origin. They don't appear linearly (one after the other) in the table like you'd expect. – Adam Feb 28 '15 at 00:11
  • The straight forward way should work, I used to do it many times, can you post some screenshot of the storyboard and how you configure these cells? – oren Feb 28 '15 at 17:30

2 Answers2

1

iOS7 doesn't support self-sizing cells, implementing heightForRowAtIndexPath: and returning the correct height is the right way to do it.

dan
  • 9,695
  • 1
  • 42
  • 40
  • Based on researching this, that was my assumption as well. Which is why I implemented the heightForRowAtIndexPath method. That, however, still yields all three cells visually stacked on top of each other. I can step through the debugger and verify that it is calling the code that should return the correct cell height for each of the different types of cells. Unfortunately it still doesn't work on iOS7, even though everything I've done in the past, and everything I've found about this on the net indicates that it should work. – Adam Feb 27 '15 at 23:48
0

Do you calculate height in "tableView:heightForRowAtIndexPath:" ? Maybe you should try to do it in "tableView:estimatedHeightForRowAtIndexPath:", because being dequeue cells copts from storyboard