UIWebView on UITableView prevents tablecell Selection

回眸只為那壹抹淺笑 提交于 2019-12-13 04:27:53

问题


I have a UIWebView on my tablecells. There are large content and it should be scrollable.

But the webview prevents Tableview didselect delegate. How to overcome this. Ihf I make userinteractionenabled=NO; scrolling is not working.

Any solution please help. Thanks in advance.


回答1:


Try using the override of hitTest

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
    id hitView = [super hitTest:point withEvent:event];

    if (hitView == self) {
        return nil;
    } else {
        return hitView;
    }
}



回答2:


Your design is definitely bad: Apple explicitly says in the UIWebView class reference, that you should not add UIWebViews to table cells. Also, as the web view internally manages an UIScrollView, which captures all the touches. So the only way to do what you want is to subclass UIWebView and override the touch management methods. This is also not advisable, as UIWebView is one of the few classes which are not to be subclassed according to Apple.

You have to seriously reconsider your design pattern.




回答3:


I recommend adjusting the size of the cell to the content size of the web view. Then set webView.scrollView.scrollEnabled to NO.

This allows the user to scroll through the whole content just in the table view. Two nested scroll views scrolling in the same directions are not advisable because the user can't easily define where the scrolling happens.

As for the selection behavior, I guess you'll have to decide whether you want cell selection or webView interactivity (link tapping etc). If you go for cell selection, setting webView.userInteractionEnabled = NO should work.



来源:https://stackoverflow.com/questions/22386877/uiwebview-on-uitableview-prevents-tablecell-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!