Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Help with NSTableViews

Help with NSTableViews
Thread Tools
techtrucker
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Dec 18, 2005, 07:58 AM
 
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. )
     
bewebste
Senior User
Join Date: Mar 2000
Location: Ithaca, NY
Status: Offline
Reply With Quote
Dec 19, 2005, 11:17 PM
 
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.
     
techtrucker  (op)
Senior User
Join Date: Feb 2003
Location: USA
Status: Offline
Reply With Quote
Dec 20, 2005, 06:13 PM
 
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 Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 03:51 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,