2012-03-13 17 views
0

我有一個登錄屏幕,當用戶名或密碼不正確時,會生成警報。現在,當用戶按下「確定」時,它將返回到登錄屏幕,但不會清除文本字段,並且仍然有以前的輸入。如何清除警報生成後的文本字段,我們按「確定」

如何將其刪除?

我警報味精代碼:

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

    [message show]; 

感謝。

+1

使用alertview委託方法 - - (無效)alertView:(UIAlertView中*)alertView clickedButtonAtIndex :(NSInteger)buttonIndex ..... if(buttonIndex == 0)然後確定按下...並清除文本框然後.... – Prathiba 2012-03-13 05:48:49

回答

2

您應該設置delegateself

你的警告是:

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

非常感謝...現在它工作。 – user1253637 2012-03-13 05:57:00

+0

@iNoob +1快速回答:) – 2012-03-13 06:01:00

+0

@ParthBhatt謝謝:D – iNoob 2012-03-13 06:01:22

0
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (buttonIndex == 0) 
    { 
     //cancel clicked ...do your action 
    } 

} 
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:@""]; 
    } 
} 
+1

'委託:nil'將不起作用。 – iNoob 2012-03-13 05:58:41

+2

抱歉忘了改變這一點。 :) – hchouhan02 2012-03-13 06:02:51

+0

@ HChouhan02:你的回答與iNoob不同嗎? – 2012-03-13 06:04:17

0

試試這個在您的登錄屏幕去viewWillDisappear,讓你文本字段爲零,它可能解決您的問題

相關問題