在 XCode 中检测 UIWebView 表单提交
我已经阅读了这里的帖子,但无法完全适应我的需要。我有:
-(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将
UIWebView
的委托设置为实现shouldStartLoadWithRequest
、[myWebPage setDelegate:self]
的对象,假设该类添加了子视图是您想要接收shouldStartLoadWithRequest
消息的视图you have to set the delegate of
UIWebView
to be the object that implementsshouldStartLoadWithRequest
,[myWebPage setDelegate:self]
, assuming that class that adds the subview is the one you want to receive theshouldStartLoadWithRequest
message将
myWebPage
的委托设置为实现的对象(在您的情况下可能是 self)Set
myWebPage
's delegate to the object that implements (in your case probably self)