How to get UITextField Tap Event?

Azhar picture Azhar · Apr 6, 2012 · Viewed 41.2k times · Source

I am trying to show UIAlertView on Tap or Click of UITextField for both IPad and IPhone. I make an IBAction and Attach it with Tap Down event of UITextField.

But its not working correctly, means not always, in case of iphone and not working in-case of iPad

- (IBAction) TopuchState
{
    //function code
}

please help How could I do this.

enter image description here

Answer

Lucien picture Lucien · Apr 6, 2012

As you are already subscribed to be UITextField delegate, implement this method:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert" message:@"Alert Message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];
    [alert show];

    return YES;
}