views:

45

answers:

1

I am trying to get a label to show over part of the grey-space in a grouped UITableView, but it only appears if the label is in a cell. I have tried adding the label as a subview of both the ViewController and the tableView and bringing it to front, but in either case it only shows over the white-space of a cell, not over the grey-space of the background. I know that I am a complete noob at Obj-C and iPhone dev and that this is a really stupid question, but I would really appreciate any help.

My code:

CGRect cgRct = CGRectMake(180, 20, 100, 50);

label = [[UILabel alloc] initWithFrame:cgRct];

label.text = @"Editting On";

label.textColor = [UIColor redColor];

label.hidden = TRUE;

//Display label

[tableView addSubview:label];

[tableView bringSubviewToFront:label];

A: 

There is probably a way to get this to work, but I'm betting that what you're trying to do is much simpler than you're making it. So, maybe explain what you want to do.

The first thing I see is you've set the hidden property to TRUE (you should be using YES, instead of TRUE by the way). If the label is hidden, you won't be able to see it, so either remove that line or change its parameter to NO.

Next, I should point out that you can add custom views for the table header and footer. You can even use custom views for section headers and footers. If what you want is a custom cell, then you'll want to either code that by hand or create a custom cell view in Interface Builder and then load it dynamically.

If what you are wanting, however, is to overlay the entire view with another view, then it will work to add the view to the top level controller's view--which is to say if you have a navigation based app, for example, you can access the navigation controller and add your view as a subview.

[[[self navigationController] view] addSubview:label];

HTH.

Matt Long
Sweet, thanks man. This works perfectly. Also, just to make myself look a little less like an idiot i know i had set hidden to true - I set it to NO later and the label didn't show until i used your suggestion.
spaceZombieHampster