ios - 删除 UITableView 中页眉/页脚/单元格之间的分隔

标签 ios swift uitableview

我对单元格之间的线条有疑问,它不想消失。

我试过以下方法

  • 在代码和 Interface Builder 中将分隔符样式设置为 .None
  • contentView 的框架 CGRect 的大小增加 1px。
  • 页眉、页脚和单元格的
  • clipToBoundstrue

无论我做什么,我似乎都无法摆脱两者之间的界限: Table

启动我的 TableView:

@IBOutlet weak var tableView: UITableView! {
    didSet {
        tableView.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
        tableView.clipsToBounds = true
        tableView.separatorInset = UIEdgeInsetsZero
        tableView.separatorStyle = .None

        if let nib = NSBundle.mainBundle().loadNibNamed(LobbySliderHeaderCollectionReusableView.classIdentifier, owner: self, options: nil).first as? LobbySliderHeaderCollectionReusableView {
            tableView.tableHeaderView = nib
        }
    }
}

...

extension LobbyViewController: UITableViewDataSource {

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return categoryChunks.count
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 1
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        var cellType: GameCollectionCellType!
        if let type = cellTypes[indexPath.item] {
            cellType = type
        } else {
            var isNot: GameCollectionCellType? = nil
            if let lastType = cellTypes[indexPath.item] {
                isNot = lastType
            }

            cellType = GameCollectionCellType.randomItem(isNot)
            cellTypes[indexPath.item] = cellType
        }

        let chunk = categoryChunks[indexPath.section][indexPath.row]

        let cell = tableView.dequeueReusableCellWithIdentifier(GameCollectionViewCell.classIdentifier, forIndexPath: indexPath) as! GameCollectionViewCell
        cell.configureWithGames(chunk)
        let color = waveColors[indexPath.section % 2]
        cell.fillColor = color
        cell.clipsToBounds = true

        return cell
    }

    func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let lh = tableView.dequeueReusableCellWithIdentifier(LobbyHeader.classIdentifier) as! LobbyHeader

        lh.fillColor = waveColors[section % 2]
        lh.contentView.clipsToBounds = true

        if categories.count > 0 {
            let cat = categories[section]
            lh.title.text = cat.name
            lh.showMore.setTitle("%@ items".localizedStringWithParameters(["\(cat.games.count)"]), forState: .Normal)
            lh.tag = section
        } else {
            lh.title.text = ""
        }
        lh.sizeToFit()

        return lh
    }

    func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let lf = tableView.dequeueReusableCellWithIdentifier(LobbyFooter.classIdentifier) as! LobbyFooter

        let i = section % 2 == 0 ? 1 : 0

        let color = waveColors[i]
        lf.waveView.fillColor = color
        lf.waveView.clipsToBounds = true
        lf.contentView.clipsToBounds = true

        let bgColor = waveColors[section%2]
        lf.contentView.backgroundColor = bgColor

        return lf
    }

    func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 30
    }

    func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 10
    }

}

大厅标题单元格(页脚和单元格类似):

class LobbyHeader: UITableViewCell {

    @IBOutlet weak var title: UILabel!
    @IBOutlet weak var showMore: UIButton!
    var fillColor: UIColor = UIColor.clearColor() {
        didSet {
            contentView.backgroundColor = fillColor
        }
    }

    var showGames: (()->())?

    class func nibForView() -> UINib {
        return UINib(nibName: classIdentifier, bundle: nil)
    }

    override func prepareForReuse() {
        super.prepareForReuse()

        title.text = ""
        showMore.setTitle("", forState: .Normal)
    }

    override func awakeFromNib() {
        super.awakeFromNib()

        backgroundColor = BackgroundColors.defaultBackgroundColor
    }

    @IBAction func showMoreAction(sender: UIButton) {
        if let showGames = showGames {
            showGames()
        }
    }

}

最佳答案

您的单元格 View 似乎来自 Xib。 xibs 中的 UITableViewCell 组件通常在底部有 1 个像素的边距(在 contentViewtableViewCell 本身之间)。

尝试在 cell.contentView 中添加一个 subview ,使背景 View 的高度比 contentView 大 1 个像素。

关于ios - 删除 UITableView 中页眉/页脚/单元格之间的分隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35508203/

相关文章:

iphone - 将参数传递给新的ViewController

ios - Cordova |从 iOS 上的麦克风获取直播

objective-c - iOS - AVPlayer - 获取当前 FPS/帧率

swift - Xcode 如何成功访问程序无法访问的数据?

ios - 无法将类型 "ViewController.Type"的值转换为预期的参数类型 "UIViewController"

iphone - UISearchDisplayController 和 UITableView 原型(prototype)单元格崩溃

ios - 如何在 iOS 上禁用 viewController 一段时间?

swift - 如何在相机中绘制线节点并保持与iPhone中的测量应用程序相同的尺寸?

ios - UITableViewCellStyle 字幕自动布局从 iOS 10 到 iOS 11 的变化?

iphone - 将数据从 SINGLE nsmutablearray 添加到 UITableView 的 2 个部分