|
|
Help with NSTableViews
|
|
|
|
Senior User
Join Date: Feb 2003
Location: USA
Status:
Offline
|
|
I'm having a problem with using two NSTableviews in a window. You click on a table, and you either get the selected row, or -1 if no row is selected. If you click off the table onto the other table, a row is left "selected" in grey in the first table. If you go back and click on that "greyed" row the table doesn't respond. You have to click twice on the table in order to get the selected row.
See short QT movie:
http://homepage.mac.com/stevewoodward/FileSharing5.html
The problem is I'm trying to fill the shared detail fields on the left using tableViewSelectionDidChange. Since clicking on the greyed out row doesn't change the current selection, I need a way to respond to the click even if the currently selected row doesn't change. Yes, I have tried it with "Allow Empty Selection" enabled and disabled. I suspect I need to be looking for something related to first responder?
BTW, I know the interface is a mess, and breaks all kinds of interface guidelines. I am porting a Windows app and was asked to keep the GUI consistent. I'll gladly do that to help someone switch!
Thanks for any tips!
(
Last edited by techtrucker; Dec 18, 2005 at 08:07 AM.
)
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status:
Offline
|
|
Yes, what's actually happening here is that the first responder for the window is changing, but the selection in the table view is not. Unfortunately, AppKit doesn't really have a notification that gets sent out when the first responder changes. I have gotten around this in the past by subclassing NSWindow and overriding the makeFirstResponder method to send out its own notification. It looks something like this:
Code:
NSString* WindowDidChangeFirstResponderNotification = @"WindowDidChangeFirstResponderNotification";
@implementation MyWindowSubclass
-(BOOL)makeFirstResponder:(NSResponder*)newResponder
{
NSResponder* oldResponder = [[self firstResponder] retain];
BOOL returnValue = [super makeFirstResponder:newResponder];
if(oldResponder != [self firstResponder])
{
[[NSNotificationCenter defaultCenter] postNotificationName:WindowDidChangeFirstResponderNotification object:self];
}
[oldResponder release];
return returnValue;
}
@end
You can then sign up to observe this notification from your other controller, and it can update the window just like the user had changed the selection.
|
|
|
|
|
|
|
|
|
Senior User
Join Date: Feb 2003
Location: USA
Status:
Offline
|
|
Thank you so much for the informative reply! I knew what the basic problem was but didn't know the right way to work around it. Having spent some time in RB recently I found myself looking for the equivelant of "gotFocus" in Cocoa...
Again, you were a lot of help, thanks!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|