繁体   English   中英

UITableViewCell 清除背景 - 分组 UITableView

[英]UITableViewCell clear background - Grouped UITableView

我正在尝试在分组表中显示我的数据,如下所示:

在此处输入图像描述

如您所见,我通过在viewDidLoad中编写以下代码清除了表格的背景视图:

customerTable.backgroundView = nil;  

同样在我的xib中,我已经清除了我的桌子的背景。

cellForRowAtIndexPath中,我为每个表格单元格设置了背景颜色。

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

结果,我得到了上面的 output。

我面临的问题是我在每个单元格中都遇到了黑角 我知道这与细胞的背景有关,但对我没有任何作用。 我还尝试清除单元格的背景编写以下代码行:

    cell.backgroundView = nil;  

尝试

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

我面临着同样的问题。 并且知道它与细胞的背景无关。

问题在于 tableview 的背景导致了这个奇怪的角落,所以

self.tableview.backgroundColor = [UIColor clearColor];

viewWillAppear将解决问题:)

在 cellForRowAtIndex 方法中清除背景应该可以工作

[cell setBackgroundColor:[UIColor clearColor]];

还尝试清除 viewWillAppear 中的背景,如果发生奇怪的事情,请清除项目并重建。

试试这个代码......

customerTable.separatorColor = [UIColor clearColor];

尝试

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

{

  cell.backgroundColor = [UIColor clearColor];

}

试试吧:

将单元格背景视图设置为 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