Pregunta

I've looked in many places and it seems everyone uses IB. I like it, but find it more fun writing it all out. This being said, I'm having difficulty dropping my keyboard after editing is done. Here's an example.

-(void)textStuff
{

    UITextField *someField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];//not true size
}

Here I've tried the resign firstresponder and even a BOOL to say are you editing, YES, then make that keyboard first responder dangit....oh, you're done editing...good, now resign that first responder.....none has worked as of yet. Any help would be greatly appreciated.

Thanks

¿Fue útil?

Solución

1).

[self.view endEditing:YES];

2).
you set the delegate method.

 SOMEFIELD.text =delegate;

And .h file

@interface yourViewController  : UIViewController<UITextFieldDelegate>

and in .m file you add the delegate method of the textfield

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
        [textField resignFirstResponder];
        return YES;
    }

Otros consejos

all you have to do is set someField's delegate your view controller and implement following method,

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top