【问题标题】:How do I remove the border from a grouped UITableView's cell?如何从分组的 UITableView 单元格中删除边框?
【发布时间】:2013-04-07 23:16:05
【问题描述】:

底部的白色小条纹真的与设计格格不入,我似乎不知道如何去除它。

This 的问题得到了很高的评价,表示要这样做:

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

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

【问题讨论】:

    标签: ios objective-c uiview uitableview


    【解决方案1】:

    将此添加到您的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;
    
    }
    

    【讨论】:

    • 好的,很高兴为您提供帮助'user212541',请检查我的编辑以了解为什么您提供的代码不起作用!
    【解决方案2】:

    试试看

    self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    

    【讨论】:

    • 稍微解释一下会有用! :)
    猜你喜欢
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-23
    相关资源
    最近更新 更多