简体   繁体   English

UITableViewCell 清除背景 - 分组 UITableView

[英]UITableViewCell clear background - Grouped UITableView

I am trying to display my data in a grouped table as below:我正在尝试在分组表中显示我的数据,如下所示:

在此处输入图像描述

As you can see I have cleared the background view for the table by writing the following code in viewDidLoad :如您所见,我通过在viewDidLoad中编写以下代码清除了表格的背景视图:

customerTable.backgroundView = nil;  

Also in my xib I have cleared the background of my table.同样在我的xib中,我已经清除了我的桌子的背景。

In cellForRowAtIndexPath I have set the background color for each table cell.cellForRowAtIndexPath中,我为每个表格单元格设置了背景颜色。

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.结果,我得到了上面的 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;  

Try尝试

customerTable.backgroundColor = [UIColor clearColor];
customerTable.opaque = NO;
customerTable.backgroundView = nil;

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问题在于 tableview 的背景导致了这个奇怪的角落,所以

self.tableview.backgroundColor = [UIColor clearColor];

in viewWillAppear will solve the issue:)viewWillAppear将解决问题:)

Clearing the background in the cellForRowAtIndex method should work在 cellForRowAtIndex 方法中清除背景应该可以工作

[cell setBackgroundColor:[UIColor clearColor]];

try also to clear the background in the viewWillAppear and if something weird happens, clear the project and rebuild.还尝试清除 viewWillAppear 中的背景,如果发生奇怪的事情,请清除项目并重建。

Try this code.....试试这个代码......

customerTable.separatorColor = [UIColor clearColor];

Try尝试

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

{

  cell.backgroundColor = [UIColor clearColor];

}

Just try with it:试试吧:

Set the cell background view to YourcellImage & cells background color to clear color.将单元格背景视图设置为 YourcellImage & 单元格背景颜色以清除颜色。

- (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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM