一切都正常现在的问题是,当我向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所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)