当用户点击 GO 时,如何关闭 ModalViewController?

发布于 2024-09-28 19:31:28 字数 908 浏览 9 评论 0原文

我有一个视图和一个按钮。当按下按钮时,我会呈现一个模态视图控制器,其中有一个 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 技术交流群。

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

发布评论

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

评论(2

—━☆沉默づ 2024-10-05 19:31:28

首先确定成功登录后网页将您带到的 URL,假设它是

http://website/logedin

. Implement UIWebViewDelegate, and detect when a request is made to that address:

- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
  if ([[request.URL absoluteString] isEqualToString:@"http://website/logedin"]) {
    [self dismissModalViewControllerAnimated:YES];
    return NO;
  }
  return YES;
}

First determine the URL the webpage takes you to on successful login, let's say it's

http://website/logedin

. Implement UIWebViewDelegate, and detect when a request is made to that address:

- (BOOL)webView:(UIWebView *)wv shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
  if ([[request.URL absoluteString] isEqualToString:@"http://website/logedin"]) {
    [self dismissModalViewControllerAnimated:YES];
    return NO;
  }
  return YES;
}
如若梦似彩虹 2024-10-05 19:31:28

您可以尝试使用下面的示例代码;


@interface WebViewController : UIViewController  {
}

UIWebViewDelegate 具有很少的委托方法,您必须在 WebViewController.m 中实现它(例如)。


-(void) webViewDidStartLoad:(UIWebView *)webView{
}
-(void) webViewDidFinishLoad:(UIWebView *)webView{
    -(void) webViewDidFinishLoad:(UIWebView *)webView
}
-(void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
}

Before this, you have to set the delegate for UIWebView from Interface Builder.

you can try with below sample code;


@interface WebViewController : UIViewController  {
}

UIWebViewDelegate having few delegate methods, you have to implement it in WebViewController.m (for eg).


-(void) webViewDidStartLoad:(UIWebView *)webView{
}
-(void) webViewDidFinishLoad:(UIWebView *)webView{
    -(void) webViewDidFinishLoad:(UIWebView *)webView
}
-(void) webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
}


Before this, you have to set the delegate for UIWebView from Interface Builder.

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