The current project runs under cocos2d v2.
I have a simple UITextField added to a CCLayer.
Whenever, the user touch the textField, a keyboard appears.
Then when the user touch the “return” button, the keyboard disappear and clears the input.
What I tried to do is to make the same thing when the user touches anywhere outside the UITextField.
I did find a method and it works :
- (void)ccTouchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch* touch = [touches anyObject];
if(touch.view.tag != kTAGTextField){
[[[[CCDirector sharedDirector] view] viewWithTag:kTAGTextField] resignFirstResponder];
}
}
However, this method doesn’t call the function :
- (BOOL)textFieldShouldReturn:(UITextField *)textField
I use this function to do some calculation and clear the input. Therefore, I would like ccTouchesBegan to enter this textFieldShouldReturn when the textfield is “resignFirstResponder”.
From the Apple docs:
So it is only called when the user taps the return button.
I would rather create a method for the calculation and input clearing, and call that method whenever you want it to be called. Example: