Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MickeyT

macrumors member
Original poster
Apr 26, 2010
92
0
Newcastle, United Kingdom
Hello

I have just seen that the UIColor groupTableViewBackgroundColor has been deprecated in iOS6. This was used so that a view could have the same background as a group-styled table view.

On searching the internet I came across a proposed solution on stackoverflow (http://stackoverflow.com/questions/12452810/is-grouptableviewbackgroundcolor-deprecated-on-ios-6), which is to put an empty table view onto a view and place all the other sub views on top of it, and then set the style to Grouped.

Then, when this view is loaded, because the table view is empty, you get the grey lined background but without any table view cells in it.

I have done this, and it works, but the table view that you drag out of the object library in Xcode is full of preset example table view cells. It makes viewing the real content of the view pretty awful (see screenshot).

Is there any way to blank the table view so that it is empty and therefore completely transparent so that I can work in interface builder without all the preset stuff spoiling the canvas?

Thank you.
 

Attachments

  • Screen Shot 2013-03-03 at 12.14.35.png
    Screen Shot 2013-03-03 at 12.14.35.png
    44.1 KB · Views: 159
Last edited:
I'm not sure of the answer to the question of how to create a blank tableview in IB. I always do this in code and don't set the delegate or dataSource.

The reason for the deprecation of the color is that the table view background is a gradient. This was implemented first on iPad when it came out in iOS 3.2. They did the same thing for iPhone (I think) with iOS 6.0.

You may have to look closely but the grey background on iPad and now the striped background on iPhone is a gradient from top to bottom. This effect can't be captured in a UIColor, I guess.
 
Perhaps that's the answer - there are examples of doing it in code via that link as well, and given that it isn't meant to offer any functionality it would be pretty easy to do. I also see there is a "send to back" method as well so it will be easy to put the table view behind the text fields and labels.

There were suggestions at the link to capture the background as an image, but that seems to be a bit complex.

For info, this is just so when a cell in a table view is clicked and a "detail" view is loaded, the detail view has a consistent background color (like in the settings app - although I think the detail view in there is perhaps a table view as well).
 
I noticed that - I have reference libraries for iOS 5.1, iOS 6.0 and iOS 6.1 and it doesn't have the red writing against this in any of them.

But I get a yellow warning in Xcode telling me it has been deprecated, and when you load the view the background is just white rather than the grey lines.
 
No problem.

So I suppose the upshot is that programmatically creating the table view is the best approach to achieve the grey background whilst not having the example cell clutter in interface builder.

Thanks everyone.
 
Huh, that's interesting. I guess (once again) Apple's Docs are behind the times. Thanks for clarifying that!

Apple's documentation department is getting further and further behind.

I did a search in the frameworks, and found this in the header files:


Code:
// Group style table view backgrounds can no longer be represented by a simple color.
// If you want to have a background in your own view that looks like the table view background,
// then you should create an empty table view and place it behind your content.
+ (UIColor *)groupTableViewBackgroundColor; // This method will be deprecated during the 6.0 seed program

I've seen a few other things that are flagged as deprecated in code in iOS 6.0, but not in the docs. That's pretty poor. Warning us about deprecated methods is a very important job for the documentation.
 
In the spirit of answer completeness for anyone reading through this in the future and doesn't know, I added this code to the viewWillAppear method of the view controller, and it works a treat:

Code:
UITableView *backgroundTableView = [[UITableView alloc] initWithFrame:[[self view] bounds] style:UITableViewStyleGrouped];
[[self view] addSubview:backgroundTableView];
[[self view] sendSubviewToBack:backgroundTableView];

Edit: probably should be in viewDidLoad actually
 
Last edited:
You can use insertSubview:atIndex: to put the tablewview where you want in one call. Also, I set the resize mask so it resizes when the device rotates.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.