Wednesday, June 19, 2013

Detect and show alert if user skip any text field to give entry

I think it is an interesting tricks to detect if used skip any text field to give entry. We can do this using a TextField delegate method

- (void)textFieldDidEndEditing:(UITextField *)textField;

Suppose your app has so many text fields  and it is very common that user may skip any text field to give entry. You can change the background colour of the text field immediately the user skips. Then the user will be aware of it .

The code is given below.



- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if([textField.text length]==0)
    {
        textField.backgroundColor=[UIColor yellowColor];
    }
    else
    {
        textField.backgroundColor=[UIColor whiteColor];
    }
    
}

I hope this post will be helpful to you . 

Happy Coding 

Mahboob