Bug 7220 - UIColor.GroupTableViewBackgroundColor seems to be broken
Summary: UIColor.GroupTableViewBackgroundColor seems to be broken
Status: RESOLVED INVALID
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.99.x
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-09-17 09:04 UTC by Manuel Koetter
Modified: 2012-09-18 19:09 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED INVALID

Description Manuel Koetter 2012-09-17 09:04:31 UTC
UIColor.GroupTableViewBackgroundColor does not return the expected color. Views that are of this color by default however are painted in the correct color.
The class below creates a list of all colors that are predefined in UIColor. When built with MonoTouch 5.99.04 the cell with background color UIColor.GroupTableViewBackgroundColor appears white instead of the grey with stripes as expected.


public class ColorBugViewController : UITableViewController
{

	public override void ViewDidLoad ()
	{
		base.ViewDidLoad ();
		TableView.Source = new ColorListSource();
	}

	public class ColorListSource : UITableViewSource
	{
		private string _cellIdentifier = "ColorListSourceCell";
		private List<PropertyInfo> colorProperties = new List<PropertyInfo>();

		public ColorListSource()
		{
			foreach(PropertyInfo propertyInfo in typeof(UIColor).GetProperties())
			{
				if(propertyInfo.PropertyType == typeof(UIColor))
				{
					colorProperties.Add(propertyInfo);
				}
			}
		}

		public override int RowsInSection (UITableView tableView, int section)
		{
			return colorProperties.Count;
		}
		
		public override UITableViewCell GetCell (UITableView tableView, NSIndexPath indexPath)
		{
			UITableViewCell cell = tableView.DequeueReusableCell(_cellIdentifier);
			if(cell == null)
			{
				cell = new UITableViewCell(UITableViewCellStyle.Default, _cellIdentifier);
			}
			cell.TextLabel.Text = colorProperties[indexPath.Row].Name;
			cell.TextLabel.BackgroundColor = UIColor.Clear;
			cell.ContentView.BackgroundColor = (UIColor)colorProperties[indexPath.Row].GetValue(null, null);
			return cell;
		}
		
		public override int NumberOfSections (UITableView tableView)
		{
			return 1;
		}
	}
}
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-09-18 07:55:09 UTC
This seems to be a change in iOS6.

With the following ObjectiveC code I see this behavior (I also see the same with your test code in MonoTouch):

Clear background: on iPad5, iPhone6 and iPad6.
Striped background: on iPhone5.

@interface ColorListSource : NSObject<UITableViewDataSource>
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
@end

@implementation ColorListSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.textLabel.text = @"GroupTableViewBackgroundColor";
        cell.textLabel.backgroundColor = [UIColor clearColor];
        cell.contentView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    }
    return cell;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UITableViewController *tabViewCtrl = [[UITableViewController alloc] init];
    UITabBarController *tabCtrl = [[UITabBarController alloc] init];
    
    NSArray *t1 = [[NSArray alloc] initWithObjects:tabViewCtrl, nil];
    [tabCtrl setViewControllers:t1];
    
    tabViewCtrl.tableView.dataSource = [[ColorListSource alloc] init];
    
    UIWindow *window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
    window.rootViewController = tabCtrl;
    [window makeKeyAndVisible];    
    
    return YES;
}

@end
Comment 2 Manuel Koetter 2012-09-18 09:52:32 UTC
Shouldn't UIColor.GroupTableViewBackgroundColor match the default background color of a grouped UITableView? The documentation reads:
"Returns the system color used for the background of a grouped table."
(http://developer.apple.com/library/ios/documentation/uikit/reference/UIColor_Class/Reference/Reference.html#//apple_ref/occ/clm/UIColor/groupTableViewBackgroundColor)

With MonoTouch 5.99.04 grouped tables by default still appear with the striped background on a iPhone while UIColor.GroupTableViewBackgroundColor is UIColor.Clear.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2012-09-18 19:09:12 UTC
In this case it seems like the documentation is lacking (at best) - it does not correspond to how it actually behaves.

StackOverflow has several questions (and answers) about this exact topic:
http://stackoverflow.com/a/5407867/183422
http://stackoverflow.com/questions/8475097/iphone-grouptableviewbackgroundcolor-alternative-for-ipad
http://stackoverflow.com/questions/5088813/ipad-grouptableviewbackgroundcolor-broken