繁体   English   中英

如何从分组的UITableView的单元格中删除边框?

[英]How do I remove the border from a grouped UITableView's cell?

在此处输入图片说明

底部的白色小条纹确实使该设计脱颖而出,我似乎无法弄清楚如何将其删除。

这个问题得到了很高的评价,据说可以做到这一点:

cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

但这也从我的背景中删除了灰色(使用setBackgroundColor:设置),所以它也不起作用。

将此添加到您的viewDidLoad:以删除表格边框:

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

我对您的问题不太了解,但是我建议您检查单元格背景视图的高度,就像测试将图像作为单元格背景视图一样,并检查白线是否仍然存在:

cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imageName.png"]]autorelease];

// ------

您提供的代码不起作用,因为您正在创建一个新的空白UIView并将其设置为单元格背景!正确的方法如下:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *CellIdentifier = @"ApplicationCell";

    UITableViewCell *cell = (UITableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {

        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

        UIView *myBackgroundView = [[UIView alloc] init];
        myBackgroundView.frame = cell.frame;
        myBackgroundView.backgroundColor = [UIColor greenColor]; <== DESIRED COLOR

        cell.backgroundView = myBackgroundView;

    }

    return cell;

}

试试吧

self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;

暂无
暂无

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

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