I have a grouped UITableView whose cells' content is dynamic. I need to calculate the actual height I need for each cell in cellForRowAtIndexPath: method. I'm testing in both iOS 7 and iOS 8 devices and I'm finding that in iOS 8 the method heightForRowAtIndexPath: is called when cellForRowAtIndexPath: returns (and then, I have cell's height updated), but it is not called in iOS 7 (so all cell's height is always the same).
I wasn't able to find a solution for this problem... please, could somebody help me?
Thanks in advance
Your premise is faulty. If you are doing this correctly, then in both iOS 7 and iOS 8 (and in all systems before that, in fact), heightForRowAtIndexPath: is called before your call to cellForRowAtIndexPath:. In general what happens is that heightForRowAtIndexPath: is called for every row, before the first call to cellForRowAtIndexPath:. That way, the table has enough information for layout before it starts generating cells.
If you are seeing a difference in behavior, it may be because you are also using the estimatedRowHeight, which does behave differently in iOS 8 vs. iOS 7. So the easy solution is: don't do that.
Related
In iOS 11 This is a pretty big change in behaviour of UITableview and existing code/or below iOS11 may work differently.
When i insert data in tableview row, row behaves weird like jumping or scrolling up and down.
I solved my issue:
In iOS 11, UITableView uses estimated heights by default. This is a big change in behaviour and existing code may work differently. Just put 0 to tableview property estimatedRowHeight.
yourTableView.estimatedRowHeight = 0.0
I'm building an app that has very complex and dynamic UITableViewCells (similar to facebook's app). Each cell is very complicated and has dynamic heights (which are always changing as things happen)
Would it be better to use the autolayout method (self.tableView.rowHeight = UITableViewAutomaticDimension) or calculate the height of each cell manually using heightForRowAtIndexPath?
For extremely complicated cells, which route should I go?
As Far as, I suggest and using since Xcode 6.4 that UITableViewAutomaticDimension works much better than calculating the height manually.
One thing, I notice that if you have content in UITableViewCell that changing constantly then you don't go for calculating the height manually because every time cellForRowAtIndexPath will call and height will be calculated accordingly.
So, in that case, you will get a lag while scrolling up / down. That's the reason UITableViewAutomaticDimension is best.
I have developed an app which has almost same UI as of Facebook and in that I have used UITableViewAutomaticDimension and it works smoothly.
Here is an app, which you can look at it. Dancinglog
Update
If you can say then I can show that particular code in that I have managed 5 different types of UITableViewCell having different views and contents.
After creating a universal app on Xcode 6, I have managed to create a UI collection view which displays 2 cells in the width of an iPhone. However when viewed on iPad, it shows 4 cells with lots of padding around the cells.
How can i change the size of cells on an iPad so that 3 cells are shown with minimal padding. I want to leave the iPhone size alone.
So far i have used the storyboard to set the cell size. I have a added a custom cell size of 158pts by 158pts which works perfectly with iPhones. I cannot find this code in the Objective C code. How can I set an individual different size for iPad.
This is what it looks like on iPhone.
https://www.dropbox.com/s/md1sn4z3k78i5s1/iphone.png
and this is what it currently looks like on iPad. The wrong way.
https://www.dropbox.com/s/0x2n9i8v6gvlfnc/ipad.png
I want to get rid of the Grey padding and increase the cell sizes so there are only 3 cells with the same padding as on the iPhone version.
I am a real beginner so any help is much appreciated.
I am answering my own post as I believe that the only way to do this is to use a standard ViewController and place a UICollectionView on top. This way you can add different UICollectionViews for the different Size Classes on Xcode 6.
At this point you can set different sizes for cells on iPad size classes to iPhones ones.
There maybe an easier way to use a UICollectionViewController but i am unaware of it, please let me know below.
EDIT
I have since found out this can be completed using the UICollectionViewController by using constraints and by increasing the cell when used on iPads by code.
I have an app that has a list of UITableViewCells. By default, the cells are set to a certain height (lets say 100) to show only some basic information. When the user clicks on a cell the height changes to 150 to show more actions that were previously not seen. This works without a problem on iOS 7.0.0-7.0.5. I'm testing on an iPhone 5s running iOS 7.1 beta 5 and seeing some drawing issues with the cells.
Here's how it looks on iOS 7.0... versions which is what is expected. When the cell is collapsed, the buttons that are positioned past the height of the cell are hidden and when the cell is expanded to a height to show the buttons, they are visible.
Cell expanded:
The following is the cell when collapsed:
Here are the issues I'm seeing with iOS 7.1 beta. Im curious if this is just something that is a problem with the beta or if I'll have to rethink how this is being coded currently. As far as I can tell this has been present since the first beta of 7.1.
As you can see, the button which was previously hidden is now still showing even though the cell is collapsed.
Is this an issue with the beta that anyone else has seen or is this expected behavior now? Thank you for you help!
Try setting clipsToBounds=YES in your cell as it may be drawing outside of it bounds.
cell.clipsToBounds =YES
Also check that the cell height is actually collapsed.
I am having a strange issue that i am unable to solve. In my Storyboard, i have set the height of a custom UITableViewCell to be 100.
But when i run the program, the height is not hundred, its 90 and i don't know why. The issue wasn't there until i updated the project to iOS 7. It might be the AutoLayout but Auto layout was already enabled when my app was running on iOS 6 SDK.
Can anyone point out what could be the problem and how i can fix it? Thanks!
Is this the only cell that is supposed to have a row height of 100? If not, I'd try changing the row height attribute of the table view itself.
If this is the only cell, another thing I'd check is if any of your constraints were changed when the project was updated to iOS 7. If you have any ambiguous or conflicting constraints set, they'll show up if you click the yellow/red indicator to the side of the scene in question.
The last thing to check would be if you're calling
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
anywhere. I doubt that's the problem, but you never know.