我有一个登录屏幕,当用户标识或密码不正确时,会生成警报。现在,当用户按下“确定”时,它返回登录屏幕,但不清除文本字段,仍然有前一个输入。
如何删除它?
我的警报消息代码是:
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Login Failed"
message:@"Login id or password is incorrect"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
感谢。
答案 0 :(得分:2)
您应该将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:@""];
}
}
答案 1 :(得分:0)
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
//cancel clicked ...do your action
}
}
答案 2 :(得分:0)
在.h文件中添加UIAlertViewDelegate
并将其添加到.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:@""];
}
}
答案 3 :(得分:0)
在您的登录屏幕中尝试这个,转到viewWillDisappear并使textfield为nil,它可以解决您的问题