开发者

NSTextField resigning first responder

I'm trying to have my text field resign first responder when the user is done editing it, like when they hit enter. The delegate method is getting called but what I have now doesn开发者_JAVA百科't work, what is the proper way to go about doing this?

- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText *)fieldEditor
{
    [fieldEditor resignFirstResponder];
    return YES;
}


From the docs on the -resignFirstResponder method:

Use the NSWindow makeFirstResponder: method, not this method, to make an object the first responder. Never invoke this method directly.

This code should do it:

[myWindow makeFirstResponder:nil];


- (void)controlTextDidEndEditing:(NSNotification *)obj {

   [self.window makeFirstResponder:view];
}

where "view" is the parent NSView of your NSTextView control.


I believe you are looking for the NSControl delegate method:

- (void)controlTextDidEndEditing:(NSNotification *)notif

Implement this method in your NSTextField delegate (easily set in IB).

Then your request to change the responder, such as

[self.window selectNextKeyView:self]

should work.


I am no expert in iPhone programming yet but the method you need to implement is "textFieldShouldReturn" implemented like this:

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜