问题描述
有人试过吗?对我来说最困难的部分是让UITableViewCell的高度与UIWebView的高度相同。通过调试代码,我注意到UITableViewCell的委托(用于获取单元格高度的heightForRowAtIndexPath)在调用UIWebView的一个(webViewDidFinishLoad)之前被称为。解决这个问题的任何解决方案?
Has anyone tried it? The hardest part for me is to get the height of the UITableViewCell to be the same as that of the UIWebView. By debugging into the code, I noticed that the delegate for UITableViewCell (heightForRowAtIndexPath for getting the height of the cell) is called before the one (webViewDidFinishLoad) for UIWebView is called. Any solution to work around that?
非常感谢!
推荐答案
我在iTunesU斯坦福iPhone应用程序开发课程上看到了这个场景。它在第16讲结束时显示,来自
I saw this scenario demonstrated once on the iTunesU Stanford iPhone Application Development course. It's shown at the end of lecture 16, from the Spring 2009 sessions
这建议在heightForRowAtIndexPath退出之前布置单元格。这肯定会损害性能,但是你可以阻止该方法,直到UIWebView完成加载。基本上循环,直到loading属性为NO,然后在完成后返回UIWebView的高度。
This similar question on SO suggests laying out cells before heightForRowAtIndexPath exits. It would hurt performance for sure, but you could block within that method until the UIWebView is finished loading. Basically loop until the loading property is NO, then return the height of the UIWebView after it is finished.
如果您正在从互联网上加载内容,这可能会使您的应用程序暂停。如果有任何方法可以事先确定高度,那么出于性能原因,最好这样做。
If you're loading content from the Internet, this might bring your app to a screeching halt, though. If there's any way you can determine the height beforehand, you're better off doing that for performance reasons.
这篇关于UITableViewCell内的UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!