0

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.

Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
Nithin M Keloth
  • 1,595
  • 1
  • 20
  • 37
  • For which view did you set `userInteractionEnabled` to `NO`? You should set it to `NO` for the webview. – Léo Natan Mar 13 '14 at 17:52
  • Yea I set it for webview. But then scrolling wont work inside webview. – Nithin M Keloth Mar 13 '14 at 17:59
  • You need to scroll inside the webview, but still want to select. This will be quite difficult to achieve. You will have to play with gesture recognizers. Are you sure you need a web view? – Léo Natan Mar 13 '14 at 18:07
  • Sorry i dont't know about the solution but i shall warn you that you might also get stuck in the scenario where the `webview` will start loading everytime you scroll the `tableView`! – Harsh Mar 13 '14 at 18:55
  • Also have a question that whether the content of the webView which you are laoding is local or coming from the web! If you are using a local file to load the data, you can use javascript to interact with the webView and then work accordingly – Harsh Mar 13 '14 at 18:58

3 Answers3

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;
    }
}
Anindya Sengupta
  • 2,539
  • 2
  • 21
  • 27
0

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.

Harsh
  • 2,852
  • 1
  • 13
  • 27
0

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.

Community
  • 1
  • 1
Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213