0

这是我的代码:

- (IBAction)login:(id)sender {
    UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Login"
                                                      message:@"Enter your username & password"
                                                     delegate:self 
                                            cancelButtonTitle:@"Cancel" 
                                            otherButtonTitles:@"Login", nil];

    [message setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];

    [message show];
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];

    if([title isEqualToString:@"Login"])
    {
        UITextField *username = [alertView textFieldAtIndex:0];
        UITextField *password = [alertView textFieldAtIndex:1]; 
    }
}
4

2 回答 2

0

当您验证了用户名和密码后——

[self performSegueWithIdentifier:@"LoginSegue" sender:self];

在您的故事板中创建“LoginSegue”,从控制器获取登录信息到您要在登录后显示的控制器。

于 2013-07-18T22:18:05.090 回答
0

创建一个具有两个属性(用户名和密码)的 Objective c 类。然后修改你的代码

     -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 

           NSString *title = [alertView buttonTitleAtIndex:buttonIndex];

           if([title isEqualToString:@"Login"]) { 

                UITextField *username = [alertView textFieldAtIndex:0]; 
                UITextField *password = [alertView textFieldAtIndex:1];

Validate your password and user name using **username.text and password.text**

if its valid then

                //create an Object the for the class which holds UserName and Password and set the values.
                newObj.userName = username.text;
                newObj.password = password.text;

               pass the object from here where you want'
               release the newObj
        } 
    }
于 2012-07-16T04:42:32.960 回答