Pregunta

I have created login for my application. I have written alert view in iOS. Here the code:

  alertView = [[UIAlertView alloc] initWithTitle:@"Login"
                                                    message:@"Enter username and password"
                                                   delegate:self
                                          cancelButtonTitle:nil
                                          otherButtonTitles:@"Login", nil];

alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;   
[alertView show];

I want to check the user name and password to allow to view next form. If the user name and password are wrong, the alert view need to pop up always.

How to pop up the alert always when the user name and password are wrong?

Any idea or reference should be appreciated.

Thanks in Advance.

¿Fue útil?

Solución

In your view controller make sure you implement the UIAlertViewDelegate protocol

@interface MyCarsViewController () <UIAlertViewDelegate>

and then add this method:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex

to the view controller. This is where you can get a reference to the text fields in the alert and do your db check etc. To get a reference to the text fields use

textFieldAtIndex:

https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertView_Class/UIAlertView/UIAlertView.html#//apple_ref/occ/instm/UIAlertView/textFieldAtIndex:

After you check for the correct login you can present other view controllers or display another alert depending on the login results.

Hoep this helps

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top