Re: Figuring out which values are selected in an NSTableView
Re: Figuring out which values are selected in an NSTableView
- Subject: Re: Figuring out which values are selected in an NSTableView
- From: Denis Stanton <email@hidden>
- Date: Thu, 19 May 2005 06:47:57 +1200
On May 18, 2005, at 8:11 PM, Scott Anguish wrote:
I can see that selectedObjects can be sent to an instance of
NSArrayController but in my app the lines:
- (void)observeValueForKeyPath: (NSString *)keyPath ofObject:
(id)object change: (NSDictionary *)change context: (void *)context {
NSLog(@" selectedObjects = %@", [paymentController
selectedObjects]);
}
I'm not sure why you'd want to do this here.. what class is this?
Sorry, the location of my NSLog line inside observeValueForKeyPath was
unnecessarily confusing for attentive readers. I just wanted to see
what was happening with [paymentController selectedObjects] so I put it
into a piece of code that was being executed frequently. The
observeValueForKeyPath method was there to perform undo functions. I
took the undo parts out of the example code, but didn't think that
readers would find the method name surprising,
always return
selectedObjects = (null)
I guess I'm short of a binding (or two), but I don't know what.
My NSArrayController has one binding.
Content Array is bound to File's Owner (MyDocument),
Model Key Path: payments
where "payments" is an MSMutableArray
In my NSTableView each column has a binding of the form
Bind to : NSArrayController
Controller Key :arrangedObjects
Model Key Path: paymentDate
Typically, in MyDocument you'd have a method that actions on the
selection
- writeToLog
that would call [yourNSArrayController selectedObjects] and that
would return you the array of newly selected objects.
It turns out my problem was caused by a typing error way back. When I
defined the NSArrayController I wrote
IBOutlet NSArrayController *PaymentController;
This value was then passed to IB.
Later I spotted the P and changed it to
IBOutlet NSArrayController *paymentController;
Nothing in the compilation process made it obvious to me that Xcode and
IB were now dealing with two separate NSArrayControllers, named
PaymentController and paymentController.
So although I was apparently making the right connections they were to
the wrong objects.
I have now moved the code to a more appropriate place. This is what I
was trying to achieve
- (void)tableViewSelectionDidChange: (NSNotification *)aNotification {
if ([[paymentController selectionIndexes] containsIndex: [payments
count]-1]) {
Payment *payment = [[Payment alloc] init];
[self insertObject: payment inPaymentsAtIndex: [payments count]];
[paymentController setSelectionIndex: [payments count]-2];
}
}
This code ensures that my tableView never runs out of lines for data
entry, without the need to have a "Insert new line" button. If the
user reaches the bottom line, by use of the tab or return key. a new
line is appended below. My save routine will trim off any unused blank
line at the end.
Thanks for your help in eliminating what I thought was a binding error
from the puzzle until I eventually spotted the typo, or the residual
effects of the typo.
Denis Stanton
Orcon Internet Limited
(09) 480 9299
http://www.orcon.net.nz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden