是否可以在 UINavigationController 和加载在 UIWebView 中的网页之间进行通信? [英] Is is possible to communicate between UINavigationController and web page loaded inside UIWebView?

查看:34
本文介绍了是否可以在 UINavigationController 和加载在 UIWebView 中的网页之间进行通信?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 iOS 开发的新手.我会尽量解释我的问题,如果你觉得它很愚蠢,请原谅我.

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

我想知道是否可以通过单击 UIWebView 中的链接在 UINavigationController 中加载子视图.

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

进一步解释一下,假设有一个 UINavigationController 有一个子视图,该子视图有一个名为 A 的 UIWebView,还有另一个名为 B 的子视图(尚未加载).是否可以加载 B(或执行任何其他原生 Objective C 事件)当用户点击 UIWebView A 内的链接时?

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?

例如,在 iPhone 的 Instagram 应用程序中,正如我所观察到的(我可能是错的),在由 UINavigationControllers 控制的视图中有 UIWebViews.在 Web 视图中点击链接会加载一个新视图.它是如何发生的?是否可以设置加载在 UIWebView 内部的网页与父/超级 UIView 之间的通信?.

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?.

如果我迷路了,请纠正我.到目前为止,我是 iOS 开发的 n00b.如果有任何意义,还可以参考我的 API 或教程来执行此操作.提前致谢.

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.

推荐答案

如果您只想处理 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.

希望有帮助!

这篇关于是否可以在 UINavigationController 和加载在 UIWebView 中的网页之间进行通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆