UINavigationController 和 UIWebView 中加载的网页之间是否可以进行通信?
我是 iOS 开发新手。我会尽力解释我的问题,如果你觉得我的问题很愚蠢,请原谅我。
我想知道是否可以通过单击 UIWebView 内的链接来加载 UINavigationController 中的子视图。
进一步解释一下,假设有一个 UINavigationController 有一个子视图,并且该子视图有一个名为 A 的 UIWebView,还有另一个名为 B 的子视图(尚未加载)。可以加载 B (或执行任何其他本机目标) C 事件)当用户点击 UIWebView A 内的链接时?
例如,在 iPhone 的 Instagram 应用程序中,正如我所观察到的(我可能是错的),由 UINavigationControllers 控制的视图中有 UIWebViews。点击 Web 视图内的链接会加载新视图。这是怎么回事?能否在 UIWebView 中加载的网页与父/超级 UIView 之间建立通信?
如果我迷路了,请纠正我。到目前为止,我在 iOS 开发方面是个新手。如果有意义的话,还可以参考我的 API 或教程来执行此操作。提前致谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想处理 UIWebView 内的点击链接,只需为 UIWebView 实现一个委托即可。它有 webView:shouldStartLoadWithRequest:navigationType: ,每当尝试在 UIWebView 中加载任何内容时都会调用它。在此方法的实现中,您可以阻止 HTML 内容的加载并执行任何您想要的 obj-c 代码。
希望有帮助!
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!