开发者

How can I dismissModalViewController when a user hits GO?

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 authe开发者_如何学Gonticates, 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];
}


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;
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜