4

I have added a UIWebView along with some labels inside UIScrollView (using StoryBoards) by adding it as a subview and then setting the ScrollView height to show all the html content of WebView that is loaded in it using loadHtmlString.

The links in the html content are not working. A little searching revealed that Apple does not recommend putting UIWebView inside UIScrollView to avoid unexpected behaviour. But as i also have to add labels and other stuff other than the UIWebView, so i have to embed them inside UIScrollView.

Is there any way I can make the links work in the html content without violating and Apple's recommendation?

Nekto
  • 17,837
  • 1
  • 55
  • 65
Jessica
  • 1,508
  • 15
  • 25
  • did you set your UIScrollView's contentSize? – howanghk Dec 21 '12 at 19:30
  • yes of course i did that – Jessica Dec 21 '12 at 19:39
  • It is working for me, I added a UIWebView inside UIScrollView and loaded @"Google" and clicking it loads Google.com – Paramasivan Samuttiram Dec 21 '12 at 19:40
  • Can you please elaborate what you are trying is not working? – Paramasivan Samuttiram Dec 21 '12 at 19:41
  • I have retrieved a html string from a CDATA block using NSXMLParser and sent it to the WebView that is added inside a ScrollView. The html links "href" in the text that is loaded in the webview, are not working. – Jessica Dec 21 '12 at 19:45
  • NSLog the the content your sending to the UIWebView to ensure you don't have parse errors and that the links are proper URLs. – Cliff Ribaudo Dec 21 '12 at 19:48
  • Of course i have done that before posting this question. There were no parsing issues. In fact i was able to open html links of blog posts when webview wasn't added inside the scrollview. – Jessica Dec 21 '12 at 19:52
  • Bottom line... your running into the Touch Event problem I mentioned down below. That's what Apple docs say is the issue your likely to encounter. See this stack post for confirmation: http://stackoverflow.com/questions/10513130/uiwebview-in-uiscrollview-tips Me personally. I do stuff like that by putting those things into UITableViewCells. Then you get nice scrolling without too much work. – Cliff Ribaudo Dec 21 '12 at 19:56
  • Did you find a workaround ? I'm having the exact same problem.. – Abel Mar 06 '16 at 17:18

1 Answers1

0

There is no reason to put a UIWebView inside a ScrollView. UIWebView will scroll and zoom and pan the content properly as is. It is sort of redundant unless you have some other layout reasons for example combining it with some other views.

The correct way to add your labels is to add them to a UIViewController or NavigationController and have them positioned around the UIWebView and to also add the UIWebView to that as well.

Cliff Ribaudo
  • 8,932
  • 2
  • 55
  • 78
  • Yes thats what i wrote in the question that i have combined it with other views and looking for a solution. – Jessica Dec 21 '12 at 19:37
  • Without knowing the design it is hard to say what is what but You might also consider adding the labels to the html content that shows up in the web view. – Cliff Ribaudo Dec 21 '12 at 19:41
  • Its already done. I have added all my views (webview and labels) inside a scrollview. The reason i have added it in the ScrollView and not some other controller is that i want all of them to scroll together instead of separately. But the question is that the html links inside webview are not working and i want them to work. – Jessica Dec 21 '12 at 19:42
  • Yeah there might be issues with the touch events going through to the UIWebView. The scrollview is probably intercepting them so that you can scroll it around. I saw Apple didnt recommend it and didn't look into it more deeply. If they go out of the way to say not a good idea to do something, I don't. – Cliff Ribaudo Dec 21 '12 at 19:48