UITableViewCell resizing automatically when presented - ios

I have a strange problem.
When my UITableView is presented, for a brief second, the cells change their height(not much but its noticeable and i do not like it). And it only changes when the device is running IOS 8. I tried it on my device using IOS 7 and nothing happened. Anyone knows what this can be?

There may be a discrepancy between the UITableViewCell height in your xib/storyboard and the height you're specifying in the delegate method heightForRowAtIndexPath.
Edit:
If that isn't your issue, try calling that delegate method:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 60;
}
or:
Specifying a height that is not 'default' since the resizing probably has something to do with the scaling of device size.

Related

xcode 7.2 UITableViewAutomaticDimension is being set without code

I am a swift/xcode newbie, following a book app that demonstrates TableViews with prototype cells using Auto Layout. The book provides completed sample projects, so I have a project to compare to.
The table view cells use images of different heights. I followed the book exactly, used the same images, etc. But the book project displays TableViewCell rows that dynamically adjust to the height of the images, but my project does not.
// both of the projects contain this line
tableView.estimatedRowHeight = 50
// I added this line to get cell rows to dynamically adjust size
tableView.rowHeight = UITableViewAutomaticDimension
With the magic line of code added, my project works perfectly, just like the book project.
My question is why does the book project display properly without the magic line of UITableViewAutomaticDimension code? Is there an attribute setting somewhere that I might have missed? Is there some other way the table view can know to use automatic dimensions?
I have carefully checked all my constraints (they follow the book), all the attributes and sizes in the inspectors for table views, cells, frames, imageviews, and have scoured the net for possible answers. (Which is how I found out about the automatic dimension code magic.)
Does anyone know where else (other than the magic code line) xcode can be told to use automatic dimensions on cell rows? Any suggestions on where I might look to find out why two apparently identical projects product different cell row height sizing behaviours? Thanks
I have tried playing with my code to see how the tableView's cell auto layouts work. I have had these two delegates in my project to auto resize my tableView cell height,
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 44.0;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
And it was working as expected, then i just commented these two delegates and put this line in my viewDidLoad method,
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.tableView.estimatedRowHeight = 50;
}
And still it is working as previously.
So i dig a bit into this and i found out that, many developers have had reported about this similar issue you are facing, self.tableView.rowHeight = UITableViewAutomaticDimension; some time behaves weirdly.
Some times it works by just adding
self.tableView.estimatedRowHeight = 50;
(as mine is now), some times you have to add both
tableView.estimatedRowHeight = 50
tableView.rowHeight = UITableViewAutomaticDimension
And in some cases none of the above work but the two delegates that is estimatedHeightForRowAtIndexPath and heightForRowAtIndexPath.
This is what i know so far about UITableViewAutomaticDimension, if you find some other info, do share.
Thanks!
I redid the whole project over again, and now it works properly without the magic line of code. #techloverr contributed a reference here on stackoverflow that (I think) supports my theory of what is going on.
My answer theory is that the default value for cells is automatic dimensioning. This is supported by the reference above.
I think during the first project attempt, I must have manually bumped or adjusted the size of the prototype table cell while loading in the image view or label placeholders.
My theory is that this tiny change caused xcode to remove the default setting and use the new (fixed) cell row height that I accidentally created. The magic code line in turn overrode the new fixed-size "default" setting.
When I redid the whole project from scratch, I took special care to NOT bump the size of the prototype cell in any way. I used all the same constraints, code, etc. And the project built and displayed properly.
Hopefully someone else can benefit from this experience. The xcode IB is touchy!

How does one layout a UITableViewCell without using Auto Layout in iOS 8?

Apologies if this is an obvious question, but as someone who has became completely used to Auto Layout and constraints, for performance I want to try laying things out manually. However, every tutorial I look up has to do with Auto Layout instead of any manual layouts.
How do I layout a UITableViewCell without depending on Auto Layout at all? I have my nib (with Auto Layout turned off), and do I position things in an overridden layoutSubviews method? Or cellForRowAtIndexPath? How is spacing between views accomplished? Are there any general tutorials available?
I think this is a pretty good tutorial for your needs: http://jslim.net/blog/2013/03/22/ios-create-uitableview-with-custom-cell-programmatically/
However there is one more method that this tutorial does not mention:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return heightOfYourCell;
}
This one is pretty important if you want your cell to be bigger or smaller than the default 44pt.

heightForRowAtIndexPath is not called after cellForRowAtIndexPath in iOS 7

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.

Empty UITableView scrolls slowly on iPhone 4 running ios 7

Ok, I'm at a loss. I have a tableview that works fine in iPhone 5/5S, but can only manage 4 fps on an iPhone 4. I've tried every trick in the book to optimize the cells (opaque, misaligned frames, no blending, render uilabels into images, static cell heights, etc), but it didn't even move the needle. Thinking that the root cause could be somewhere else, I decided to strip out all my custom cell code so that cellForRowAtIndexPath: returns an empty (but re-used) UITableViewCell, and even that runs slow... I've tried profiling the app while scrolling the tableview, but nothing stands out at all. The only thing that seems suspicious is that if turn on CoreAnimation's Color Hits Green and Misses Red, the status bar will constantly flash between green and red as I scroll the tableview. This leads me to believe that the status bar is being redrawn every frame (or every couple of frames), but even hiding the status bar didn't improve the fps by much (maybe 4 -> 7).
So.... I'm at a loss. Anyone out there experience something like this and can point me in the right direction?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:__inboxCell];
if (! cell)
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:__inboxCell];
return cell;
}
Here's when I run a time profiler and get around 6 fps:
When I remove the system libraries, it's pretty useless. If I keep scrolling for a few minutes, the % of Parent for cellForRowAtIndexPath: will greatly exceed that of didFinishLaunchingWithOptions: (which obviously only runs once).

UITableViewCell Height Not Setting Up In StoryBoard

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.

Resources