4

I am trying to display my data in a grouped table as below :

enter image description here

As you can see I have cleared the background view for the table by writing the following code in viewDidLoad :

customerTable.backgroundView = nil;  

Also in my xib I have cleared the background of my table.

In cellForRowAtIndexPath I have set the background color for each table cell.

cell.backgroundColor = [UIColor colorWithRed:255.0/255 green:235.0/255 blue:178.0/255 alpha:1];  

As a result I am getting the above output.

The problem I am facing is the black corners I am getting in every cell. I know it has something to do with background of the cell but nothing is working for me. I also tried to clear the background of cell writing the following code line:

    cell.backgroundView = nil;  
halfer
  • 19,824
  • 17
  • 99
  • 186
Nitish
  • 13,845
  • 28
  • 135
  • 263
  • Are you creating your own UITableViewCell subclass? – Carter Jul 21 '11 at 17:23
  • 2
    What happens if you set cell.backgroundColor = [UIColor clearColor]? Are the black corners still there? – Carter Jul 21 '11 at 17:30
  • No there are no corners now. But how do I get the background color of cell as I want to set and still get no corners? – Nitish Jul 21 '11 at 17:34
  • 2
    You could try overriding how the cell is drawn or add another subview with rounded corners to the cell (while keeping the background color clear). How are you getting the rounded corners for the UITableViewCell? – Carter Jul 21 '11 at 17:39
  • I earlier considered the option you have mentioned. I was thinking may be I can place an image over the cell with round corners and then setting background color of cell as clear color. I just wanted to do it without using an image if possible. Talking about how I am getting corners in cell, I think when we clear the background view of cell, a round cornered cell is left out. The same happens in case of textfield. – Nitish Jul 21 '11 at 17:47
  • 1
    I'm not sure why the black corners are coming up then, but instead of an image you could subclass UITableViewCell and draw a rounded rect instead of the basic drawing. That should let you control the corner roundness and the entire color of the cell while getting rid of the black corners. – Carter Jul 21 '11 at 17:55

6 Answers6

8

Try

customerTable.backgroundColor = [UIColor clearColor];
customerTable.opaque = NO;
customerTable.backgroundView = nil;
Pierre
  • 10,593
  • 5
  • 50
  • 80
  • I have already mentioned that I have cleared the background of table in my xib. – Nitish Jul 21 '11 at 17:18
  • Setting `opaque` to `NO` is the key, I think. – mrueg Jul 23 '11 at 11:09
  • Hi guys. I had already tried all what Perrie has suggested before posting this question. Nothing worked for me. – Nitish Jul 23 '11 at 14:48
  • @Jolly : He is correct if it was table whose background I wanted to be clear. I have clearly mentioned, it is the cell inside the section of which I was worried about. – Nitish Jul 23 '11 at 14:50
0

I was facing the same problem. And got to know It has nothing to do with cell's background.

The issue is with background of the tableview which causes this weird corners, So

self.tableview.backgroundColor = [UIColor clearColor];

in viewWillAppear will solve the issue :)

Suresh Varma
  • 9,750
  • 1
  • 60
  • 91
0

Clearing the background in the cellForRowAtIndex method should work

[cell setBackgroundColor:[UIColor clearColor]];

try also to clear the background in the viewWillAppear and if something weird happens, clear the project and rebuild.

gdm
  • 7,647
  • 3
  • 41
  • 71
0

Try this code.....

customerTable.separatorColor = [UIColor clearColor];
Aravindhan
  • 15,608
  • 10
  • 56
  • 71
0

Try

- (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath

{

  cell.backgroundColor = [UIColor clearColor];

}
Nitish
  • 13,845
  • 28
  • 135
  • 263
Kumaran
  • 687
  • 6
  • 14
0

Just try with it:

Set the cell background view to YourcellImage & cells background color to clear color.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath             
{
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) 
    {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

        [cell setBackgroundColor:[UIColor clearColor]];
        UIImage *backgroundImage = nil;
        UIImageView *backgroundView = nil;
        backgroundImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:@"YourYellowCellImage"ofType:@"png"]];
        backgroundView = [[UIImageView alloc]initWithImage:backgroundImage];
        backgroundView.frame = CGRectMake(0, 0, 600, 80); // Over here give your cell size
        cell.backgroundColor = [UIColor clearColor];
        cell.backgroundView =backgroundView;

        [backgroundView release];   
   }
   //Over your set your Label Value    
   return cell;
}
P.J.Radadiya
  • 1,493
  • 1
  • 12
  • 21
Ajay Sharma
  • 4,509
  • 3
  • 32
  • 59