Re: Deselect keyboard focus of an NSMatrix cell
Re: Deselect keyboard focus of an NSMatrix cell
- Subject: Re: Deselect keyboard focus of an NSMatrix cell
- From: Jochen Moeller <email@hidden>
- Date: Fri, 23 Jul 2010 02:20:53 +0200
Hello Kyle,
thanks for your answer. I did as you suggested. But both -makeFirstResponder: and
-resignFirstResponder return YES after pressing Return in the textFieldCell.
So in my new test version the focus should move to an NSTextField after Return is pressed in the textFieldCell within the NSMatrix but doesn't.
Am 22.07.2010 um 22:26 schrieb Kyle Sluder:
> Jochen Moeller wrote:
>> The -makeFirstResponder: method seems not to respond.
>
> -makeFirstResponder: returns a BOOL. See the documentation for
> -[NSWindow endEditingFor:] for what to do when -makeFirstResponder:
> returns NO.
-makeFirstResponder: returns YES, see below
>>
>> I tried this:
>> 1. Same as above.
>>
>> 2. Additional a custom content view which returned YES for
>> -acceptsFirstResponder and -canBecomeKeyView.
>>
>> 3. Additional modifying the NSMatrix object: "matrix" is the outlet.
>> [ matrix setAllowsEmptySelection:YES ];
>> NSLog(@"selectedCell: %p", [matrix selectedCell]); // a valid pointer
>> [ matrix deselectAllCells ];
>> NSLog(@"selectedCell: %p", [matrix selectedCell]); // 0x0, but the focus ring remains, why ?
>
> Because the matrix is still the first responder?
May be that here the matrix is still the first responder but the last selected NSTextFieldCell is still selected although nil is returned.
>> [ matrix display ]; // the focus ring remains
>> [ window makeFirstResponder:[ window contentView ]]; // did not work.
>> // Also [ window makeFirstResponder:anotherTextField ]; did not work.
// BOOL b = [ window makeFirstResponder:[ window contentView ]]; // b = YES
BOOL b = [ window makeFirstResponder:anotherTextField ]; // b = YES
>>
>> The key focus still remains in the textfield cell of the matrix.
>>
>> Any ideas?
>
> Do you have a custom formatter or a binding set up on the matrix that
> might cause validation to fail and the field editor to refuse to
> resign first responder status?
No formatter or bindings. It's just a simple test cocoa app with an NSTabView with two tabViewItems in the window.
The first view has two NSTextField objects that work as expected, the key focus is deselected with -makeFirstResponder:contentView (custom or not) when hitting Return.
The second view has an NSMatrix with four NSTextViewCells and the last edited cell remains selected although the key focus should be set successfully to another text field in that view.
> To see if it's the field editor
> refusing to resign first responder, return a custom NSTextView
> subclass from -windowWillReturnFieldEditor:toObject: that simply
> overrides -resignFirstResponder to call through to super, and break on
> that return statement to see if the field editor's implementation is
> returning NO.
Here the overridden method:
- (BOOL)resignFirstResponder {
NSLog(@"%@ - %@", [self class], NSStringFromSelector(_cmd));
BOOL b = [ super resignFirstResponder ];
NSLog(@" resignFirstResponder: %@", b ? @"YES" : @"NO"); // YES
return b;
}
If it is useful I can send the project folder (33 kB zip file)
Thanks again,
Jochen Moeller
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden