当用户点击 GO 时,如何关闭 ModalViewController?
我有一个视图和一个按钮。当按下按钮时,我会呈现一个模态视图控制器,其中有一个 uiwebview 和顶部的导航栏。硬编码的 uiwebview 显示登录提示。一旦用户进入并输入正确的登录凭据并按键盘上的 GO,我不仅需要它对我进行服务器身份验证,还需要关闭模态视图控制器。
请注意,我输入数据的文本字段是 uiwebview 中加载的网站的一部分...
当我现在按回车键时,网页会进行身份验证,一切都很顺利,但我只需要一种方法来绑定 当他们按下“GO”时发出
[self dismissModalViewControllerAnimated:YES];
命令……有什么想法吗?
谢谢
编辑
这是我在登录视图中实现的代码:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [[NSURL alloc] initWithString: @"http://website"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url];
[webView loadRequest: request];
[request release];
[url release];
}
-(BOOL) textFieldShouldReturn:(UITextField *)textField{
[self dismissModalViewControllerAnimated:YES];
return YES;
}
-(IBAction) done{
[self dismissModalViewControllerAnimated:YES];
}
I have a view and a button. When the button is pushed, I present a modal view controller that has a uiwebview, and a navigation bar at the top. The hardcoded uiwebview shows a login prompt. Once the user goes in and enters the correct login credentials and hits GO on the keyboard, I not only need it to authenticate me into the server, but also dismiss the modal view controller.
Note the text field I enter data into is part of the website loaded in uiwebview...
When I hit enter now, the web page authenticates, and everything is peachy, but I just need a way to tie in a
[self dismissModalViewControllerAnimated:YES];
command when they hit GO...any thoughts?
Thanks
EDIT
Here is the code that I am implementing in the loginView:
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [[NSURL alloc] initWithString: @"http://website"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: url];
[webView loadRequest: request];
[request release];
[url release];
}
-(BOOL) textFieldShouldReturn:(UITextField *)textField{
[self dismissModalViewControllerAnimated:YES];
return YES;
}
-(IBAction) done{
[self dismissModalViewControllerAnimated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先确定成功登录后网页将您带到的 URL,假设它是
. Implement
UIWebViewDelegate
, and detect when a request is made to that address:First determine the URL the webpage takes you to on successful login, let's say it's
. Implement
UIWebViewDelegate
, and detect when a request is made to that address:您可以尝试使用下面的示例代码;
UIWebViewDelegate 具有很少的委托方法,您必须在 WebViewController.m 中实现它(例如)。
Before this, you have to set the delegate for UIWebView from Interface Builder.
you can try with below sample code;
UIWebViewDelegate having few delegate methods, you have to implement it in WebViewController.m (for eg).
Before this, you have to set the delegate for UIWebView from Interface Builder.