我是iOS開發新手,我正在創建一個具有本機登錄屏幕的webview應用程序。完成後,我需要關閉webview並返回到本地登錄屏幕。我已經看到這個問題的答案,但我不明白答案。這是回答後:Close UIWebView using javascript:window.close();從webview返回到原生應用程序
目前,我有這樣的:
NSURL *url = [NSURL URLWithString: @"http://mysite/redirector.php"];
NSString *postData =[[NSString alloc] initWithFormat:@"username=%@&password=%@",[_txtUsername text],[_txtPassword text]];
// Create the request object
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL: url];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: [postData dataUsingEncoding: NSUTF8StringEncoding]];
// create the web view
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
//Change Frame
webView.frame = CGRectMake(webView.frame.origin.x, webView.frame.origin.y + 20, webView.frame.size.width, webView.frame.size.height);
// Load the request
[webView loadRequest: request];
//show the webview
[self.view addSubview:webView];
我需要在上面的代碼更改爲使這項工作?
如何「通過shouldStartLoadWithRequest:
」讀取[NSURL path]
中的圖案「?
在此先感謝。
請參閱http://stackoverflow.com/questions/10992339/how-to-intercept-button-click-inside-uiwebview-on-ios。希望這是你正在尋找的。 –
謝謝,這看起來好像可能會訣竅,但我已在該頁面上添加了代碼,但是當我單擊關閉時沒有任何反應,我是否必須修改上面的代碼才能使其工作? – Benswana
如果點擊按鈕,您可以從其超級視圖中移除網頁視圖。將webView中的[webView removeFromSuperView]放入:shouldStartLoadWithRequest:用URL檢查。 –