在 XCode 中检测 UIWebView 表单提交

发布于 2024-12-29 18:15:25 字数 877 浏览 2 评论 0原文

我已经阅读了这里的帖子,但无法完全适应我的需要。我有:

-(IBAction) abouthtml
{
NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
CGRect webViewRect = frameWebSpace;
UIWebView *myWebPage=[[UIWebView alloc] initWithFrame:webViewRect];
[myWebPage loadRequest:requestObj];
[self.view addSubview:myWebPage];
}

这显示正常,但 about.html 中的“返回程序”提交按钮不起作用。

我已经尝试过,正如此处帖子中所建议的那样:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request 
navigationType:(UIWebViewNavigationType)navigationType 
{
if (navigationType == UIWebViewNavigationTypeFormSubmitted) 
{
     ....

但显然,没有任何内容将 myWebPage 链接到 webView。有人可以建议我缺少什么吗? 我需要让 webView 成为 myWebPage 的委托吗?迷茫,但又充满希望……

I've read the posts here, but cannot quite adapt them to my needs. I have:

-(IBAction) abouthtml
{
NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"about" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
CGRect webViewRect = frameWebSpace;
UIWebView *myWebPage=[[UIWebView alloc] initWithFrame:webViewRect];
[myWebPage loadRequest:requestObj];
[self.view addSubview:myWebPage];
}

This displays fine, but my "Return to Program" submit button in about.html is not working.

I've tried, as suggested in posts here:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request 
navigationType:(UIWebViewNavigationType)navigationType 
{
if (navigationType == UIWebViewNavigationTypeFormSubmitted) 
{
     ....

But obviously, nothing links myWebPage to webView. Can someone suggest what I'm missing?
Do I need to make webView a delegate of myWebPage? Confused, but hopeful...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜心 2025-01-05 18:15:25

您必须将 UIWebView 的委托设置为实现 shouldStartLoadWithRequest[myWebPage setDelegate:self] 的对象,假设该类添加了子视图是您想要接收 shouldStartLoadWithRequest 消息的视图

you have to set the delegate of UIWebView to be the object that implements shouldStartLoadWithRequest, [myWebPage setDelegate:self], assuming that class that adds the subview is the one you want to receive the shouldStartLoadWithRequest message

笔芯 2025-01-05 18:15:25

myWebPage 的委托设置为实现的对象(在您的情况下可能是 self

-webView:shouldStartLoadWithRequest:navigationType:

Set myWebPage's delegate to the object that implements (in your case probably self)

-webView:shouldStartLoadWithRequest:navigationType:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文