How can I place a UIWebView in a table view cell, yet maintain the UIWebView's scrollbars? My table view does have multiple cells and a header frame as well, and I do need it to be scrollable because it has many rows.
如何在表格视图单元格中放置UIWebView,同时维护UIWebView的滚动条?我的表视图确实有多个单元格和一个标题框架,我确实需要它可以滚动,因为它有很多行。
The text displays perfectly fine when I use UITextView and it shows scrollers as well, but the problem is that my content is rich text, so I don't have any other option but to show the content in UIWebView. Any ideas, hacks?
当我使用UITextView并且它也显示滚动条时,文本显示完全正常,但问题是我的内容是富文本,所以除了在UIWebView中显示内容之外我没有任何其他选项。任何想法,黑客?
7 个解决方案
#1
Unless Apple does something about it, this can't work. Both UITableView and UIWebView support scrollers, and they contradict with each other. UITableView scrollers take precednce so whenever a scroll operation is performed, the action is sent to UITableView instead of UIWebView.
除非Apple对此有所帮助,否则这不起作用。 UITableView和UIWebView都支持滚动条,它们相互矛盾。 UITableView滚动器采用precednce,因此无论何时执行滚动操作,操作都将发送到UITableView而不是UIWebView。
For some reason, when using UITextView with UITableView, scrollers work for both.
出于某种原因,当UITextView与UITableView一起使用时,滚动条适用于两者。
#2
The problem with adding UIWebView into a table cell is both these objects are scrollable (tableview and webview) which will create complications if not used appropriately. Does you tableview have any cells other than uiwebview? and do you need the tableview to be scrollable? In case the tableview need not be scrollable, make scrolling enabled in the webview and disabled for the tableview. That should work.
将UIWebView添加到表格单元格中的问题是这些对象都是可滚动的(tableview和webview),如果使用不当会产生复杂性。 tableview有除uiwebview以外的任何单元格吗?你需要tableview可滚动吗?如果tableview不需要可滚动,则在webview中启用滚动并为tableview禁用滚动。这应该工作。
But if you want to just display text, why not use a UITextView (though you'll face the same problem for UITextView too)?
但是如果你只想显示文本,为什么不使用UITextView(虽然你也会遇到UITextView的同样问题)?
#3
I just found this in the UIWebView documentation:
我刚刚在UIWebView文档中找到了这个:
"Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled."
“重要提示:您不应该在UIScrollView对象中嵌入UIWebView或UITableView对象。如果这样做,可能会导致意外行为,因为两个对象的触摸事件可能混淆和错误处理。”
#4
The scrollbars are added automatically when you put content in your UIWebView. Be sure to uncheck "Scales Page to Fit" in Interface builder, so the page is not rescaled when displayed.
将内容放入UIWebView时,会自动添加滚动条。请务必在“界面”构建器中取消选中“缩放页面以适合”,以便在显示时不重新调整页面。
#5
UIWebView will automatically display scrollbars when it has content that exceeds the height of the UIView.
当UIWebView的内容超出UIView的高度时,它将自动显示滚动条。
#6
You can put a UIWebView into a UIScrollView and have both scrollable by setting the canCancelTouchEvents
property of the UISCrollView to NO
. If you just flick, the UIScrollView will scroll. If you hold your finger down for a short period of time and then start to flick, the UIWebView will scroll.
您可以将UIWebView放入UIScrollView,并通过将UISCrollView的canCancelTouchEvents属性设置为NO来同时滚动。如果您只是轻弹,UIScrollView将滚动。如果您将手指放下一小段时间然后开始轻弹,UIWebView将会滚动。
#7
Try this quick hack to see if you can force the web view to show a scroll indicator: ((UIScrollView*)[webView.subViews objectAtIndex:0]).showsVerticalScrollIndicator = YES;
试试这个快速黑客,看看你是否可以强制Web视图显示滚动指示器:((UIScrollView *)[webView.subViews objectAtIndex:0])。showsVerticalScrollIndicator = YES;
The more thorough approach is to divide your cell contents into a summary and detail. Show the summary in each cell, but without details. After you select a cell, use a new screen to show the full contents of the selected cell. This completely avoids the usability issue of having a scrollable view inside of a scrollable view.
更彻底的方法是将您的单元格内容划分为摘要和详细信息。在每个单元格中显示摘要,但没有详细信息。选择单元格后,使用新屏幕显示所选单元格的完整内容。这完全避免了在可滚动视图内部具有可滚动视图的可用性问题。
#1
Unless Apple does something about it, this can't work. Both UITableView and UIWebView support scrollers, and they contradict with each other. UITableView scrollers take precednce so whenever a scroll operation is performed, the action is sent to UITableView instead of UIWebView.
除非Apple对此有所帮助,否则这不起作用。 UITableView和UIWebView都支持滚动条,它们相互矛盾。 UITableView滚动器采用precednce,因此无论何时执行滚动操作,操作都将发送到UITableView而不是UIWebView。
For some reason, when using UITextView with UITableView, scrollers work for both.
出于某种原因,当UITextView与UITableView一起使用时,滚动条适用于两者。
#2
The problem with adding UIWebView into a table cell is both these objects are scrollable (tableview and webview) which will create complications if not used appropriately. Does you tableview have any cells other than uiwebview? and do you need the tableview to be scrollable? In case the tableview need not be scrollable, make scrolling enabled in the webview and disabled for the tableview. That should work.
将UIWebView添加到表格单元格中的问题是这些对象都是可滚动的(tableview和webview),如果使用不当会产生复杂性。 tableview有除uiwebview以外的任何单元格吗?你需要tableview可滚动吗?如果tableview不需要可滚动,则在webview中启用滚动并为tableview禁用滚动。这应该工作。
But if you want to just display text, why not use a UITextView (though you'll face the same problem for UITextView too)?
但是如果你只想显示文本,为什么不使用UITextView(虽然你也会遇到UITextView的同样问题)?
#3
I just found this in the UIWebView documentation:
我刚刚在UIWebView文档中找到了这个:
"Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled."
“重要提示:您不应该在UIScrollView对象中嵌入UIWebView或UITableView对象。如果这样做,可能会导致意外行为,因为两个对象的触摸事件可能混淆和错误处理。”
#4
The scrollbars are added automatically when you put content in your UIWebView. Be sure to uncheck "Scales Page to Fit" in Interface builder, so the page is not rescaled when displayed.
将内容放入UIWebView时,会自动添加滚动条。请务必在“界面”构建器中取消选中“缩放页面以适合”,以便在显示时不重新调整页面。
#5
UIWebView will automatically display scrollbars when it has content that exceeds the height of the UIView.
当UIWebView的内容超出UIView的高度时,它将自动显示滚动条。
#6
You can put a UIWebView into a UIScrollView and have both scrollable by setting the canCancelTouchEvents
property of the UISCrollView to NO
. If you just flick, the UIScrollView will scroll. If you hold your finger down for a short period of time and then start to flick, the UIWebView will scroll.
您可以将UIWebView放入UIScrollView,并通过将UISCrollView的canCancelTouchEvents属性设置为NO来同时滚动。如果您只是轻弹,UIScrollView将滚动。如果您将手指放下一小段时间然后开始轻弹,UIWebView将会滚动。
#7
Try this quick hack to see if you can force the web view to show a scroll indicator: ((UIScrollView*)[webView.subViews objectAtIndex:0]).showsVerticalScrollIndicator = YES;
试试这个快速黑客,看看你是否可以强制Web视图显示滚动指示器:((UIScrollView *)[webView.subViews objectAtIndex:0])。showsVerticalScrollIndicator = YES;
The more thorough approach is to divide your cell contents into a summary and detail. Show the summary in each cell, but without details. After you select a cell, use a new screen to show the full contents of the selected cell. This completely avoids the usability issue of having a scrollable view inside of a scrollable view.
更彻底的方法是将您的单元格内容划分为摘要和详细信息。在每个单元格中显示摘要,但没有详细信息。选择单元格后,使用新屏幕显示所选单元格的完整内容。这完全避免了在可滚动视图内部具有可滚动视图的可用性问题。