【问题标题】:UITableView stops scrolling after sometimeUITableView 在一段时间后停止滚动
【发布时间】:2020-11-16 21:47:55
【问题描述】:

我使用从本地数据库加载数据的标准 iOS UITableView。我已经实现了委托和数据源并注册了我的 UITableView 单元格和标题,一切看起来都很好。然而,滚动几秒钟后,表格视图不再滚动,如果我滚动/摆动非常快,这种情况很快就会发生,表格视图不会响应任何触摸事件,没有滚动,没有单元格选择。我不知道做错了什么。注意:没有新的数据获取,所以一旦加载了初始数据,我就不会重新加载 tableView 数据。这是我的数据源类:TableCell 是自定义 UITableViewCell 而 HeaderCell 是自定义 UITableViewHeaderFooterView

func registerCells(tableView: UITableView) {
    tableView.register(UINib.init(nibName: tableCell, bundle: nil), forCellReuseIdentifier: tableCell)
    
    tableView.register(UINib(nibName: headerCell, bundle: nil), forHeaderFooterViewReuseIdentifier: headerCell)
    
    print("\(sourceTag) register cells")
}

func numberOfSections(in tableView: UITableView) -> Int {
    return viewModel.getNumberSections()
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return self.viewModel.getNumberRowsInSection(section)
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let data = viewModel.dataValues[indexPath.section]
    let cell = tableView.dequeueReusableCell(withIdentifier: tableCell, for: indexPath) as! TableCell
    cell.selectionStyle = .none
    let quote = data.quotes[indexPath.row]
    cell.setupWithQuote(quote, withSelectionDelegate: quoteSelectionDelegate)
    return cell
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let data = viewModel.dataValues[section]
    let headerCell = tableView.dequeueReusableHeaderFooterView(withIdentifier: enquiryCell) as! HeaderCell
    headerCell.setupData(data)
    return headerCell
}

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

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

func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
    return 161.0
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
    //print("I'm scrolling!")
    NSLog("I'm scrolling!")
}

【问题讨论】:

  • 您是从 Xcode 运行应用程序吗?你确定它没有崩溃?你确定它没有在断点处停止吗?如果两者都不是,常见的问题是从后台线程更新 UI 或进入无限循环。我认为您需要发布更多代码(TableCell 和 HeaderCell 类),以便我们可以看到 setupWithQuote()setupData() 中发生了什么

标签: ios swift uitableview


【解决方案1】:

@DonMag 评论为我指明了正确的方向。有一个委托方法被多次审查分配,这导致了一个循环问题,因此表格视图单元格呈现问题

【讨论】:

    猜你喜欢
    • 2012-10-25
    • 1970-01-01
    • 2022-08-19
    • 1970-01-01
    • 2014-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-19
    相关资源
    最近更新 更多