开发者

How to check whether an UITextfield is entered with data or not?

开发者 https://www.devze.com 2023-03-31 04:17 出处:网络
what is the default value of an uitextfield? I nee开发者_运维知识库d to implement a login page alert with message\" please enter both the fields\"

what is the default value of an uitextfield? I nee开发者_运维知识库d to implement a login page alert with message" please enter both the fields" How to implement the check condition whether username and password textfields are filled ?


Your login view will have a Username(txtUsername) and a Password(txtPwd) text fields. And a button(btnLogin).

-(IBAction)Login:id(sender)  
{
if([txtUsername.text length] !=0 && [txtPwd.text length] !=0)
{
// Navigate to view controller you want to
}
else
{
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:nil message:@"please enter both the fields" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];

[alertView show];                           
[alertView release];
}
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex == 0) {

        //OK clicked

        //Do something

    } 
    else {

    }

}


You can check when enter/return/done is pressed on keyboard using textFieldShouldReturn delegate..

textFieldShouldReturn:

If you want to check while user is typing itself, you can use

textFieldDidBeginEditing

and

textField:shouldChangeCharactersInRange:replacementString:

Read UITextFieldDelegate documentation...


You can check length of entered text. For example:

if ([usernameTextField.text length] == 0 && [passwordTextField.text length] == 0) {
      // inform user to enter both data
}
0

精彩评论

暂无评论...
验证码 换一张
取 消