Jim
07-05-2012, 08:05 PM
I need help with Objective C. In this case I've created a UIAlertView with UIAlertViewStyleLoginAndPasswordInput style and I want to be able to check if the login data is correct, but I don't know how to check it after a button has been pressed.
- (IBAction)loginPushed:(id)sender
{
UIAlertView *loginAlert = [[UIAlertView alloc]initWithTitle:@"Login to BindingDB" message:@"Enter your login info" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[loginAlert setAlertViewStyle:UIAlertViewStyleLoginAndPassword Input];
[loginAlert addButtonWithTitle:@"Enter"];
[loginAlert addButtonWithTitle:@"Cancel"];
[loginAlert show];
[self checkLogin:loginAlert];
}
- (void)checkLogin:(UIAlertView *)loginAlert
{
//I don't know what to put in this if statement to make it work only when the "enter" button has been pressed
if () {
NSString *login = [[loginAlert textFieldAtIndex:0] text];
NSString *password = [[loginAlert textFieldAtIndex:1] text];
if (login == @"Jim" && password == @"Password") {
[self verifyLogin:true];
}
else {
[self verifyLogin:false];
}
}
}
- (void)verifyLogin:(BOOL)checkLogin {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
if (checkLogin) {
[alert setTitle:@"Login Successful"];
[alert setMessage:@"You have logged in"];
}
else {
[alert setTitle:@"Login Failed"];
[alert setMessage:@"Try Again"];
}
[alert show];
}
- (IBAction)loginPushed:(id)sender
{
UIAlertView *loginAlert = [[UIAlertView alloc]initWithTitle:@"Login to BindingDB" message:@"Enter your login info" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
[loginAlert setAlertViewStyle:UIAlertViewStyleLoginAndPassword Input];
[loginAlert addButtonWithTitle:@"Enter"];
[loginAlert addButtonWithTitle:@"Cancel"];
[loginAlert show];
[self checkLogin:loginAlert];
}
- (void)checkLogin:(UIAlertView *)loginAlert
{
//I don't know what to put in this if statement to make it work only when the "enter" button has been pressed
if () {
NSString *login = [[loginAlert textFieldAtIndex:0] text];
NSString *password = [[loginAlert textFieldAtIndex:1] text];
if (login == @"Jim" && password == @"Password") {
[self verifyLogin:true];
}
else {
[self verifyLogin:false];
}
}
}
- (void)verifyLogin:(BOOL)checkLogin {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
if (checkLogin) {
[alert setTitle:@"Login Successful"];
[alert setMessage:@"You have logged in"];
}
else {
[alert setTitle:@"Login Failed"];
[alert setMessage:@"Try Again"];
}
[alert show];
}