在启动 tableView 期间删除行

Remove lines during boot tableView

当我启动我的应用程序时,如何在启动 tableView 期间删除行? 我尝试添加 activityIndi​​cator,但他没有帮助我。

可能是我设置不正确 UIView 还是需要使用其他东西?

可能需要代码 activityIndi​​cator:

private func setLoadingScreen() {

    let width: CGFloat = 30
    let height: CGFloat = 30
    let x = (self.tableView.frame.width / 2) - (width / 2)
    let y = (self.tableView.frame.height / 2) - (height / 2) - (self.navigationController?.navigationBar.frame.height)!
    loadingView.frame = CGRect(x: x, y: y, width: width, height: height)

    self.activityIndicator.activityIndicatorViewStyle = .gray
    self.activityIndicator.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
    self.activityIndicator.startAnimating()

    loadingView.addSubview(self.activityIndicator)

    self.tableView.addSubview(self.loadingView)

}

private func removeLoadingScreen() {

    self.activityIndicator.stopAnimating()

}

最简单的解决方案是在加载之前将 UITableView 定义的 separatorStyle 属性 的值设置为 UITableViewCellSeparatorStyleNone

self.tableView.separatorStyle = .none

加载完成后,您可以将其设置回 UITableViewCellSeparatorStyleSingleLine

self.tableView.separatorStyle = .singleLine

Apple Reference

设置空 UITableView 页脚。在这种情况下,您不必切换回 separatorStyle。

self.tableView.tableFooterView = UIView()

或将 UITableView 分隔符样式设置为 .none

self.tableView.separatorStyle = .none

我想为此在 UITableView 上创建一个扩展:

public extension UITableView {
    /**
    Hides the separators which display when the table view is empty.
     */
    func hideSeparators() {
        guard tableFooterView == nil else { return }
        tableFooterView = UIView()
    }
}