views:

449

answers:

3

I want to open a panel when the user clicks on a text field. I think I should use a delegate method that responds to the click event. I found that the

- (void)textDidBeginEditing:(NSNotification *)aNotification

method does not work, and that the

- (void)controlTextDidBeginEditing:(NSNotification *)aNotification

method works, but only when I edit the text in the text field, not then I click it. If I edit the text again, this method does not work. Why?

+1  A: 

The textFieldDidBeginEditing: delegate method only gets triggered when the user starts editing the text inside the UITextField, as the method name implies.

If you want to trigger a method when the UITextField is touched, you should try this:

[textField addTarget:self 
              action:@selector(textFieldTouched:)
    forControlEvents:UIControlEventTouchDown];

- (void) textFieldTouched:(id)sender {
    // Display the panel
}
Can Berk Güder
Sorry, I think I want to use this on mac , not on iphone,How to do with it with cocoa?
jin
+2  A: 

The correct delegate method name is

- (void)textFieldDidBeginEditing:(UITextField *)textField

From the documentation:

This method notifies the delegate that the specified text field just became the first responder.

Alex
A: 

Sorry, I think I want to use this on mac , not on iphone,How to do with it with cocoa?

jin