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

有帮助吗?

解决方案

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;
    }

其他提示

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;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top