Is is possible to communicate between UINavigationController and web page loaded inside UIWebView?

◇◆丶佛笑我妖孽 提交于 2020-01-07 05:35:34

问题


I am new to iOS development. I will try my best to explain my question, please pardon me if you find it silly.

I was wondering if one can load a subview in a UINavigationController by clicking a link inside a UIWebView.

Explaining it further, let's say there is UINavigationController that has a subview and that subview has a UIWebView called A, and there is another subview(that is not loaded yet) called B. Is is possible to load B (or perform any other native Objective C event) when user taps on a link inside the UIWebView A?

For example in Instagram app for iPhone, as I have observed (I may be wrong), there are UIWebViews in views controlled by UINavigationControllers. Taping a link inside a web view loads a new view. How is it happening? Can one set up the communication between the web page loaded inside the UIWebView and the parent/super UIView?.

Please correct me if I am lost. I am a n00b in iOS development so far. Also reference me the APIs or tutorials to do this if this makes any sense. Thanks in advance.


回答1:


If you want just to handle a click-on-link inside UIWebView, just implement a delegate for the UIWebView. It has webView:shouldStartLoadWithRequest:navigationType: , which is called any time any content is attempted to be loaded in UIWebView. In the implementation of this method, you can block loading of the HTML content and perform any obj-c code, you want.

Hope that helps!



来源:https://stackoverflow.com/questions/7968743/is-is-possible-to-communicate-between-uinavigationcontroller-and-web-page-loaded

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