简体   繁体   English

如何使用带有异步功能的estimatedHeightForRowAtIndexPath? 迅速

[英]How to use estimatedHeightForRowAtIndexPath with async func? swift

I'm moving and app I had on Parse to Firebase and I ran into an issue with a cell that needs to get resized.It contains a textview that recieves data, since the text varies in size, I am using this two methods: 我正在移动并将解析到Firebase上的应用程序遇到一个需要调整大小的单元格的问题,它包含一个可以接收数据的textview,因为文本的大小各不相同,因此我正在使用以下两种方法:

    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

override func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

With Parse this worked perfectly because I would recieve the entire object that I had to pass to the DetailTableView in the MainTableView. 使用Parse可以完美地工作,因为我会收到必须传递给MainTableView中的DetailTableView的整个对象。 With Firebase, I handle it differently, I retrieve what the MainTableView needs, then I just pass a reference to the DetailTableView and again retrieve whatever I need there. 使用Firebase,我将以不同的方式进行处理,检索MainTableView所需的内容,然后将引用传递给DetailTableView,然后再次检索在那里需要的内容。 The problem seems to be that the size of the cell gets set before the async function can set the text. 问题似乎是在异步功能可以设置文本之前设置了单元格的大小。 Any ideas on how to solve this? 关于如何解决这个问题的任何想法?

Thanks in advance! 提前致谢!

我认为您可以通过调用tableView.beginUpdates() tableView.endUpdates()来包装在单元格上设置文本的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Swift:如何同时使用两个func文本字段 - Swift: How to use two func textfield at same time 如何使用“自动布局”约束将2个具有可变大小的标签放入表格单元格中,该表格单元格的高度是使用EstimateHeightForRowAtIndexPath估算的 - How to use Auto Layout constraints to fit 2 labels with variable size in a table cell which height is estimated using estimatedHeightForRowAtIndexPath "如何并行使用 Swift async\/await" - How to use Swift async/await in parallel 如何警告 Swift 中函数的调用者 - How to warn caller of a func in Swift 如何在Swift中使用dispatch_async? - How to use dispatch_async in Swift? Swift如何从UITableViewRowAction获取访问功能 - Swift How to get access func from UITableViewRowAction 如何在 Swift 中成功实现 async 和 await,什么是最好的使用方法 - How to successfully implement async and await in Swift, and whats the best method to use 如何在 Swift 中使用异步 function 的完成处理程序版本? - How to use the completion handler version of a async function in Swift? 如何从Swift中的appdelegate调用ViewController中的func? - How to call the func in ViewController from appdelegate in Swift? 如何在Swift中的func中为全局常量创造价值 - How to make value in func to global constant in Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM