tags:

views:

3256

answers:

5

I have downloaded TableView sample code '4_TableViewCellSubviews' from internet. I am trying to run this program in my way. I am trying to set my own background view color as 'lightgraycolor'. I just wanted to see the background view as lightgraycolor in this application. I don't want to make any color for TableView. i.e i want to give gray color only for the background view, not for the background of table. When i provide the code for that as '[self.view setBackgroundColor:[UIColor lightGrayColor]];' , it is changing the color for the entire table as well. But i am trying to set Color only for the view which besides on the Table. How to set background color only for the background view and not for the TableView. I know that the code which i provide to set the color background view is perfect. But., Could someone who came across with this problem, provide me suggestions what are the possibilities that we would get to occur with this issue and solution for this?

I have kept the sreenshot at the following location:

http://www.quickfiles.net/894107

NEED URGENT HELP..WAITING FOR THE SOLUTION BY GIVING YOUR PRECIOUS SUGGESTIONS...

I think most you all have misunderstood my problem. I want to have color on the space when we scroll DOWN the Table we see a empty space on the top in the background of tableview. For example, download a free news application called, "BusinessWeek". You can launch this app in your iPhone device. You can see the home screen and scroll DOWN the table there. You can see the background color as Gray color of the Table. I want to do the same way, please let me know what should i do for that?

Clave/

A: 
[tableView setBackgroundColor:[UIColor clearColor]];
Alex Reynolds
>> [tableView setBackgroundColor:[UIColor clearColor]];It doesn't work out. It's again clears color for Table as well as the background view. I can't see gray color in the background view as well.
Clave Martin
You may not have something wired up correctly. Making the tableView's background color clear will allow you to see the view's background color.
Alex Reynolds
No it's not happening for me. Could you please go to the below link and download my project and check.http://www.quickfiles.net/324924Clave/
Clave Martin
+1  A: 

In this case here, the 'view' and 'tableView' are the same actually, that's the color change doesn't work as you want it to. To convince you of that, add these 2 lines in the 'viewDidLoad' function, and look at what is output in the console when you run your program:

NSLog(@"tableView: %@", self.tableView);
NSLog(@"view: %@", self.view);
Zoran Simic
I am getting the log results as below:tableView: <UITableView: 0x1026a00; frame = (0 0; 320 387); clipsToBounds = YES; opaque = NO; autoresize = W+H; layer = <CALayer: 0xd34000>>view: <UITableView: 0x1026a00; frame = (0 0; 320 387); clipsToBounds = YES; opaque = NO; autoresize = W+H; layer = <CALayer: 0xd34000>>NOTE:I want to implement the same thing(some color only for the background "View",not for the background of table) in my project also and observing the same problem apart from the project which i have pasted in the above link.
Clave Martin
Please let me know what am i doing wrong and how to resolve it?
Clave Martin
I have corrected now to have view separate and tableview separate. The logs are not shows as :tableView: <UITableView: 0x1026a00; frame = (0 30; 320 357); clipsToBounds = YES; opaque = NO; autoresize = W+H; layer = <CALayer: 0xd345b0>>view: <UIView: 0xd1c300; frame = (0 0; 320 387); autoresize = RM+BM; layer = <CALayer: 0xd357d0>>Now the another problem is, it doesn't show the view in the background at all, so whatever i set color for view, doesn't seem to be there. It shows tableview itself for the whole view.
Clave Martin
sorry, please correct my above comment statement as "The logs are shows as :" instead of "The logs are not shows as :"
Clave Martin
A: 

You should add the tableView as a subview of the MainView. Create a ViewController class and programmatically add the tableview methods and delegate. At program start, add your tableview as a subView of the Mainview. In this way UITableView and UIView should be two distinct parts, and you should be able to change the background color properly.

EEE
Clave Martin
A: 

My problem was also same whatever the below existing query is talking about 'Gutter' color change:

http://stackoverflow.com/questions/987954/set-uitableviewcell-background-color-on-plain-style-table-view/1456085#1456085

Currently i have resolved it by the following code:

I have created a UIView and set the background color as 'Gray'. I created a TableView on top of it and connect with the tableView variable there.

When i run my app, it has shown the Gray color in the background view and also in Table. I don't want that color in Table, so added the below code as well to remove it.

in 'viewDidLoad'

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

UIView *myView = [[UIView alloc] initWithFrame:cell.frame]; myView.backgroundColor = [UIColor whiteColor]; cell.backgroundView = myView; [myView release];

cell.contentView.backgroundColor = [UIColor whiteColor];

Clave Martin
+1  A: 

Sorry, the earlier answer comment needs to modified as below steps. I am writing the solution here because some one else if they come across they can use it.

  1. In I.B, Create UIView and set the color whatever you want. Create Table on top of it. Create a TableView variable in your code and connect that with I.B Table.

  2. In viewDidLoad, add like below. myTableView.backgroundColor = [UIColor clearColor]; myTableView.alpha = 0.9; [super viewDidLoad];

  3. Add the below code in cellForRowAtIndexPath:

    UIView *v = [[UIView alloc] initWithFrame:cell.frame];
    

    v.backgroundColor = [UIColor whiteColor]; cell.backgroundView = v; [v release]; // If you want accessory type add this below line .. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

  4. Build and Run you application.
Clave Martin