文本字段 - 确保用户至少填写一个字段

时间:2014-05-12 13:05:54

标签: ios7 uitextfield

在我的应用中注册时,我想确保用户填写一个字段。 虽然对用户来说无关紧要。这就是我遇到的问题。我得到的壁橱是强制用户填写一个特定的文本字段,如下面的代码。这不是我猜的最好的用户体验:)任何知道该做什么的人?

 self.saveButton.delegate = self;


- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if ([self.RandomTextField.text isEqualToString:@""]) {
        self.saveButton.enabled = NO;
    } else {
        self.saveButton.enabled = YES;
    }
    return YES;
}

2 个答案:

答案 0 :(得分:1)

在sign_up按钮的点击事件中

- (IBAction)SignUPBtn:(UIButton *)sender {
      if([textfeld_Email.text length]>0)
    {
        //sign up
    }
    else
    {
        if([textfeld_Pswd.text length]>0)
        {
         //sing up   
        }

        else{
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Please enter your email and pass" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];

        }
    }  


}

答案 1 :(得分:1)

- (IBAction)SignUPBtn:(UIButton *)sender {

   if(txtName.text.length==0 && txtEmail.text.length==0 && txtPass.text.length==0)
   {
         [[[UIAlertView alloc] initWithTitle:@"" message:@"Please Fill Atleast One Field" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]show];

   }
   else
   {
      //Write Your Code here. this else called only if anyone of three textfield is filled up.

   }
}