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.
Related
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!
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.
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.
I am making an app where I need to use UITableViews to display content in an organized fashion, but since I updated to iOS 8 and Xcode 6 I have been getting a mystery gray box over almost the entire view. This can be seen in the image below. This does not happen on every UITableView, just some (with no apparent pattern).
In iOS 8, you must specify a height in the UITableView's delegate:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 44.0;
}
In iOS 7 and earlier, a default was accepted. See this link for more information.
This is definitely a bug in XCode6-Beta2. I found a workaround. Select the storyboard, and go to the File Inspector utility. Uncheck the option "Use Auto Layout" then click "Disable Size Classes" in the popup.
Auto Layout seems to be quite broken in beta2. Once you turn off Size Classes, the mysterious "ambiguous scrollable content" warnings will also go away.
I was able to turn Size Classes and Auto Layout back on afterward and the gray rectangle is still gone, but everything is in the wrong place after losing the Size Classes info. It's a mess.
Strangely enough, it has to do with the Table View Separator Style. If you set that to None, the problem will go away. But of course, then you have no separators! If you want to use Single Line separators, you have to manually specify a cell height in -tableView:heightForRowAtIndexPath:.
I have no idea why this is the case, but I am guessing it has something to do with the new self-sizing table rows. Time to do some research :)
In iOS 8 the row height can be set automatically for you.
All you have to do is set a top and bottom constraint to the contentView of the UITableViewCell, like this (notice the constraints):
By doing this, the row height will be automatic and you won't need to set a fixed height.
This fixes the gray background color you have encountered.
Resource: http://www.shinobicontrols.com/blog/posts/2014/07/24/ios8-day-by-day-day-5-auto-sizing-table-view-cells
I'm using a nav bar orchestrated set of tableviewcontrollers to display a hierarchy of data. The bottom level of data is displayed in a custom tableviewcell, which has its content described in a xib, and results in a required cell height larger than the default. I posted another question on how to programmatically extract the resulting cell height, but no usable answers, so I now implement heightForRowAtIndexpath to return a hardcoded value that is the height in the xib attributes panel. But, when the table is displayed with more rows than can fit in the normal display size (480h,320w), the bottom row is chopped off as expected, but I can't scroll it to see the rest of the row. I've searched rather extensively, but nothing has helped. I poked at various attributes (tableview sizes, scrollingEnabled, etc.) but they all seem as expected values (e.g., scrollingEnabled is true). One post suggested that no scrolling would occur unless the contentSize was larger then the frame, so I looked at those values, and it sounds promising, in that my frame size is a typical 460h x 320w, but, my contentSize is 0 x 0! Further searching (e.g., "setting contentSize" or "contentSize is 0") didn't clear anything up. I thought contentSize was computed for free from the table row count and their heights, so how could I be getting 0? Even going back to allowing a default row height by not implementing heightForRowAtIndexpath still resulted in a 0 contentSize. Some searches suggest turning off autoLayout for the custom table cell, but still the same. So, what might be going awry? Thanks for any thoughts or guidance.
Update: Sorry, I confess! I had originally been developing on a mac mini with a regular USB mouse, where scrolling in the simulator was left button down and drag. I recently switched to an iMac with the magic mouse. I'm now so used to just dragging my finger on the mouse to scroll code, web pages, etc., that I didn't think to try clicking and holding the left mouse "button", and then dragging the mouse. When I did, everything worked as expected. I had really thought things were hopeless when any similar variables/values in the app on the mini were equal to those on the iMac, but it was just me getting tricked by fancy technology. Sorry for the distraction.
set your tableView's frame and your cell's frame correct,and implement
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath in your UITableView to give a right height. If that doesn't work try set your tableView.autoresizingMask to UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
which can help you with the size of the tableview
I had a similar problem. My tableView would't scroll when the content exceeded the tableViews frame.
The problem for me was that I had "Use Autolayout" checked but no constrains on the tableView. Adding vertical and horizontal space constrains on the tableView fixed my problem