ios – 错误:UITableView跳转到顶部与UITableViewAutomaticDimension

ios – 错误:UITableView跳转到顶部与UITableViewAutomaticDimension,第1张

概述我正在使用UITableView与estimatedRowHeight和UITableViewAutomaticDimension.另外我正在使用NSFetchedResultsControllerDelegate来反映更改. 一切都正常现在的问题是,当我向CoreData添加一些记录时,NSFetchedResultsController调用它的委托,但出现意想不到的事情. TableView每 我正在使用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所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1115162.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存