iOS 7+ UITableView with 3 Different Prototype Cells of Varying Height - ios

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.

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

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

Related

UICollectionView that functions like a tableview

The designer came back with a layout that displays information differently.
Is it possible to make my UICollectionView function like a UITableView? Where each cell takes up one row and there is only one column?
Everything I found on the net seems to be about the opposite, making a UITableView be a UICollectionView
Actually, its very simple. Just make the width of the UICollectionViewCell equal to the width of the view.

UITableViewCell (ReusableCell) are not Identifing correct constraints

I've used Visual Format Language (VFL) to set constraint of the UITableViewCustomCell's subviews.
its working fine when I scrolling my TableView slowly or normal speed.
But its now working when I scrolling TableView fast.
there are 3 different scenario comes.
TitleLabel --> one line text only
DetailTextLabel --> 0, 1 or 2 line only
see this screen shot which is looking correct when I scrolled it slowly
And when I scroll it fast then its not taking correct constraints
And one thing. Log does not displaying any warning. means that all constraints are complete and correct.
I've tried [self updateConstraintsIfNeeded]...etc so many things.
and its working correct when I used Different cell identifier for particular condition. but I don't want to use different-different cell Identifier.
For Autolayout to work correctly it only requires that all constraints are set and that there are no conflicts amongst the constraints. If you fulfill these promises and ensure that your table view rowHeight property is set to UITableViewAutomaticDimension (i.e. self-sizing cells), then everything should work properly. Also, a common mistake is to update the cell data inside of tableView:cellForRowAtIndexPath: instead of tableView:willDisplayCell:forRowAtIndexPath:. As stated in the documentation, the latter method gives the delegate to override state-based properties. Ensure that your table view is using self sizing cells.

Auto Layout in UITableView for dynamic row heights with table view cell from universal storyboard

So far I've had some success in calculating dynamic table cell layouts with auto layout. And so far, I have maintained different storyboards for iPhone and iPad. I would now like to consolidate them into a single storyboard per app. I'm currently stuck at a point where my height calculations do no longer function.
The trouble is apparently that the table view cell as dequeued from the storyboard is still at its fixed storyboard size (relative to a specific device, i.e. iPhone in my case) when the calculation is first required. It will be resized to fit the actual device (iPad in my case) when the table is displayed. But tableView:heightForRowAtIndexPath: is called before that and therefore does its calculation based on the wrong table cell width.
Is there a good way to solve this problem? It seems as if this accepted answer also isn't immune because its instructions also only mention the cell in isolation from its table view.
First, instantiate an offscreen instance of a table view cell, one
instance for each reuse identifier, that is used strictly for height
calculations.

UILabel dynamic height iOS 7 with Views Below

Similar things have been posted a hundred times here at SO, but I just cannot get my specific situation to work.
My specific problem is:
I have a UILabel that gets various amounts of text dynamically from a plist.
This label is inside a prototype cell in a table & I can get the cell to grow according to the amount of content.
I can get the 8 views that are below that cell in my prototype cell layout (two UIImageViews, a couple of other UILabels, and a few UIButtons) to move down based on the size of the dynamic UILabel.
Here's the problem:
When I scroll down to see the full cell on the 3.5" iPhone in the simulator, the cell cuts off before the bottom of the cell, and on the 4" iPhone it is perfect.
When I fiddle with the height of the UITableView in the storyboard, it either cuts off more or not but it never hits the same way in both devices.
Oddly, when I make the tableView shorter in the storyboard, it makes the view longer (and the cell shows up) in both devices.
There's just no rhyme on the space below the last element in the prototype cell, and I can't seem to equalize it at all.
Any help would be appreciated.
I can't believe this is so difficult for me.

Align labels of a custom UITableViewCell when editing

I have an UITableView with several prototype cells and some of the editable cells are basic cells and some customs.
(XCode 4.6.1 / iOS 6.1)
My question is how to automatically align the labels of the custom cells (in the Storyboard) like it's done by default for basic cells' textLabel?
Here's two screenshots to understand what I mean:
By the way, I've obviously Google'd before and didn't find anything but maybe I missed something, as I'm a newbie on iOS :)
Edit: you probably already understood the screens, but in case of: the "add" cell is a default basic cell and the "delete" cells are custom cells with my own UILabel (with the wrong alignment).

Resources