【问题标题】:How to Clear UITextfield Text and Ok button in UIAlertView in IOS?如何在 IOS 的 UIAlertView 中清除 UITextfield 文本和确定按钮?
【发布时间】:2015-03-19 06:14:53
【问题描述】:

我创建了密码验证。密码创建成功将显示一个UIAlertView,当用户按下确定时,密码文本字段将被清除。怎么做?请问有什么例子吗?

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    添加UIAlertViewDelegate协议:

    @interface YourViewController : UIViewController <UIAlertViewDelegate> 
    

    显示警报视图使用:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"TITLE_HERE" 
                                                    message:@"ALERT_MESSAGE HERE." 
                                                    delegate:self 
                                                    cancelButtonTitle:@"OK" 
                                                    otherButtonTitles:nil];
    [alert show];
    

    用户点击OK后,该方法会自动调用:

    - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
        // the user clicked OK
        if (buttonIndex == 0) {
            // do something here...
            yourTextField.text = nil;
        }
    }
    

    【讨论】:

      【解决方案2】:

      你的问题不清楚。如果您希望在显示 UIAlert 后密码字段文本为空,请添加以下代码使您的密码字段为空。

      yourTextField.text = ""
      

      这是一个例子。

      if(passwordValid==YES)
      {
      UIAlertView *passwordValidated = [[UIAlertView alloc] initWithTitle:@"Password Validated!"
                                                                                                message:@"Your password is successfully validated. Press OK to continue"
                                                                                               delegate:nil
                                                                                      cancelButtonTitle:@"OK"
                                                                                      otherButtonTitles:nil];
      
      yourTextField.text = "";
      
      
      [updateMessage show];                        
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-02-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多