HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 错误:UITableView跳转到顶部与UITableViewAutomaticDimension大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用UITableView与estimatedRowHeight和UITableViewAutomaticDimension.另外我正在使用NSFetchedResultsControllerDelegate来反映更改.

一切都正常现在的问题是,当我向CoreData添加一些记录时,NSFetchedResultsController调用它的委托,但出现意想不到的事情. TableView每次都会突然滚动到顶部.

NSFetchedResultsControllerDelegate

func controllerWillChangeContent(controller: NSFetchedResultsController) {
    tableView.beginupdates()
}

func controllerDidChangeContent(controller: NSFetchedResultsController) {
    tableView.endupdates()
}

func controller(controller: NSFetchedResultsController,didChangeObject anObject: AnyObject,aTindexPath indexPath: NSIndexPath?,forChangeType type: NSFetchedResultsChangeType,newIndexPath: NSIndexPath?) {
        switch type {
        case .Insert:
            tableView.insertRowsATindexPaths([newIndexPath!],withRowAnimation: .NonE)
            break

        case .update:
            tableView.reloadRowsATindexPaths([indexPath!],withRowAnimation: .NonE)
            break

        case .delete:
            tableView.deleteRowsATindexPaths([indexPath!],withRowAnimation: .NonE)
            break

        default: break;
        }
    }

通过谷歌搜索,我发现很少的answers,人们建议使用tableView:heightForRowATindexPath:但是因为我的单元格高度是动态的.所以我该怎么做?

解决方法

tableView.reloadData()
if tableView.numberOfRowsInSection(0) > 0
{
      let indexPath = NSIndexPath(forRow: 0,inSection: 0)
      self. tableView.scrollToRowATindexPath(indexPath,atScrollPosition: .Top,animated: truE)
}

大佬总结

以上是大佬教程为你收集整理的ios – 错误:UITableView跳转到顶部与UITableViewAutomaticDimension全部内容,希望文章能够帮你解决ios – 错误:UITableView跳转到顶部与UITableViewAutomaticDimension所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。