как очистить текстовое поле после того, как сгенерировано предупреждение и мы нажимаем «ОК» - PullRequest
0 голосов
/ 13 марта 2012

У меня есть экран входа в систему, и когда ID пользователя или пароль неверны, генерируется предупреждение. Теперь, когда пользователь нажимает «ОК», он возвращается к экрану входа в систему, но не очищает текстовое поле и все еще имеет предыдущий ввод.

Как это убрать?

мой код для сообщения:

UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Login Failed"
                                                      message:@"Login id or password is incorrect"
                                                     delegate:nil
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];

    [message show];

Спасибо.

Ответы [ 4 ]

2 голосов
/ 13 марта 2012

Вы должны установить delegate на self

Ваше предупреждение будет:

    UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Login Failed"      message:@"Login id or password is incorrect" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [message show];

и используйте:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex==0)
     {
         [yourTextField setText:@""];
     }
}
0 голосов
/ 13 марта 2012

попробуйте на экране входа в систему перейти к viewWillDisappear и сделать текстовое поле равным нулю, это может решить вашу проблему

0 голосов
/ 13 марта 2012

добавить UIAlertViewDelegate в .h файл и добавить это в .m файл

UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Login Failed"
                                                      message:@"Login id or password is incorrect"
                                                     delegate:self
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];

[message show];


- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex==alertView.cancelButtonIndex)
     {
         [yourTextField setText:@""];
     }
}
0 голосов
/ 13 марта 2012
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        //cancel clicked ...do your action
    }

}
...