iOS 8 gray box over UITableView - ios

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

Related

Xcode 8 Layout Issue - Why is the UITableCell contentView above the actual content?

Xcode 8 Upgrade has broken many of my auto-layout settings - such a pain. Anyway - Here is a simple example. My UITableView was working fine - but since the upgrade now the images are missing - without any other changes being made to this table view. Investigation shows something really weird. Though the cell contains the image view and text with correct constraint etc within the cell layout (in pink)
The image view frame is seen above the cell...
Also when I click on content view the content is in the wrong place (shown in grey) - above the (pink) cell frame itself.
My Image View Settings are:
For now the solution to displaying the missing images is to move the square frame down until in comes back into the pink area
Am I going crazy? Is this a bug caused in the Xcode 8 update? What should I do?

iOS: Size classes not changing for different sizes

I am trying to build a UI for my app using the storyboard in xcode.
I have recently changed the look and would like to have things slightly different for iPad as to iPhone. For example I want the cell height to be one height on ipad and another on iphone, with each different size adversely affecting where the label within the cell is positioned etc.
The annoying thing is I got this all working on a xib, but using the storyboard, I will build everyhting how I want it in compact width regular height for iphone, then go and build the UI for ipad in regular width regular height. Then go back to check things out for iphone and it has completely adopted what I have done in the regular regular size class.
This is infuriating, it effectively is pointless in having the size class, I may aswell use any any size class, but I don't want to. Images included below gives you a good visual representation.
so here I have made the UI for iphone
Then here is the ipad before and after I make changes
Then head back to regular regular (iphone) and you can see the size for the cell has changed
If I was to then change it back to how it was before, and the go to ipad I would be looking at the first ipad image i included above. So annoying, how can I get it to work with the different size classes?
You can't use sizeclasses to change the height of tableviewcell.None of the tableviewcell's properties can be modified by the sizeclasses.
When you choose a label or anything else that can be modified by the size classes ,you would see an "installed" checkbox at the bottom of the attributes inspector.You can install or uninstall a label in different size classes.
But when you choose a tableviewcell or a tableviewcell's subview,you would not see this checkbox.It don't make sense a tableviewcell appear in one size class but disappear in another.
You have to use tableView's delegate method to change the height of a tableView.

Detail Text and Accessory Don't show [duplicate]

I'm trying to use Auto Layout for a custom Table View Cell in my app.
I can't seem to get the constraints quite right.
I layed the labels out in the custom Table View Cell, but the labels are still getting cut off. Any ideas?
Thanks! Will post anything else needed. Tried to show needed info in picture below:
Debugging in Xcode. Somehow what shows in Simulator looks different than in Xcode debug.
Here's the width of my TableView shown:
UPDATE:
The problem here was related to what user matt said in the accepted answer, but I wanted to make the Q&A a bit clearer now that I have it figured out for anyone else that comes across this.
In his initial comment, he mentioned the Xcode View debugging, which was great and I was able to dig into a little bit more. Its called the Assistant Editor: Device Preview, where you are able to see the layout and layers of what is onscreen to see if maybe you have labels overlapping or going offscreen based on the device it is running on. If you want to check multiple device sized, just hit the plus icon in the lower left hand corner of this picture.
This helped me find overlapping layers and sizing issues with the TableView. I was able to see how it looked on each device size.
What also helps here sometimes to use the Pin menu. Sometimes the labels can run off screen because it doesn't know where the constraints of the cell are based on the device size. So your label can run offscreen if the label is based off of a landscape layout but the device is an iPhone 5 and is in Portrait for example. This is the Pin menu:
Hope that makes sense and gives some more color to the problem. Let me know if you have any questions at all, thanks for the help everyone!
The problem is that you are using auto layout but you have not done anything about sizing the table view. The table view here is not your view controller's view; it is a subview. Your view controller's view is automatically sized to the size of the device / window, but its subviews are not automatically resized. So you are ending up with the table view much too wide for the device; the whole table is sticking off into space on the right side.
Use a trailing space from the right side of your labels to the edge of their superview, and set it to greater than instead of equals with a value of ~ 5
Review the constraints of your tableview with the View. Draw cell border, label border and tableview border with different colors to know which elements do not display correctly.
Ex:
#import <QuartzCore/QuartzCore.h>
...
cell.layer.border.width = 1;
cell.layer.border.color = [UIColor blackColor].CGColor;
The thing that worked for me to solve views being clipped was to uncheck "Constrain to margins" in Auto Layout.

iOS: Tableview with custom cells does not scroll

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

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