Re: Very basic table binding blind spot
Re: Very basic table binding blind spot
- Subject: Re: Very basic table binding blind spot
- From: Michael Swan <email@hidden>
- Date: Fri, 03 Aug 2012 05:11:59 -0400
Erik,
I've only made a custom subclass of NSArrayController once and that was a long time a go to do some custom thing that I don't remember now.
Normally I add an array to the appropriate view controller that has the table data in it and then bind the NSArrayController's content to that array. Then for the table I bind the columns to arrayController.arrangedObjects.someKey. Unless I need to do some sort of custom work when adding or removing objects I make add and remove buttons that connect directly to the methods of NSArrayController. As long as I don't make any changes to the array in the view controller behind KVO's back the binding magic takes over and I don't need to make a data source at all and the only delegate stuff I have to deal with is stuff like selecting and sorting/re-sorting. Make sure your array controller prepares content.
Hope that helps,
Mike Swan
ETCP Certified Entertainment Electrician
http://www.theMikeSwan.com
"Change itself is not painful it is resistance to change that causes pain."
On 3 Aug, 2012, at 1:16 AM, email@hidden wrote:
> Message: 12
> Date: Thu, 02 Aug 2012 22:16:20 -0700
> From: Erik Stainsby <email@hidden>
> To: "email@hidden (Apple)" <email@hidden>
> Subject: Very basic table binding blind spot
> Message-ID: <email@hidden>
> Content-Type: text/plain; charset=windows-1252
>
>
>
> I do so wish there was a Complete Idiot's Guide to Cocoa Table Bindings … The very flexibility which I know must be their great virtue tends to obscure the clear path from my sight more often than not. Forest, trees, trees, forest … Oh! Something shiny!
> ---
>
> So tonight I have an NSArrayController (RSTableArrayController) which I have populated with dictionary objects of the form:
>
> [self.content addObject:[NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects: key, [mvo valueForKey:key],nil] forKeys:[NSArray arrayWithObjects:@"label",@"value",nil]]];
>
>
>
> For this simple two column data I have a two column table, using Table View Cells (I'm going to have visual objects in place of the 'label' later on).
> I have set the identifier for the tableView columns very imaginatively to "label", and "value".
> The array controller is also < NSTableViewDataSource, NSTableViewDelegate >. I have implemented the following two delegate methods:
>
> - (NSInteger) numberOfRowsInTableView:(NSTableView *)aTableView {
> return self.content.count;
> }
>
> - (id) tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex {
> NSString * identifier = [tableColumn identifier];
> NSDictionary * dict = [self.content objectAtIndex:rowIndex];
> NSLog(@"%s- [d] %@: %@", __PRETTY_FUNCTION__, __LINE__, identifier,[dict valueForKey:identifier]);
> return [dict valueForKey:identifier];
> }
>
> In the nib, I have an ArrayController object of the class described above RSTableArrayController. It is wired up as the delegate and dataSource for the tableView.
>
>
> And here is where I get lost time and again, tracing the appropriate path to the content and it's constituent data parts and binding them to the appropriate element in the tableView.
>
> » Scroll View
> » Table View
> » Table Column
> » Table Cell View
> » Static Text
> Text Field Cell
>
> Given that the delegate method is called -[tableView: objectValueForTableColumn: row:] I should expect to bind the arrayController's objectValue in the Bindings Inspector to the ?node? in the object browser. Do I need to do more than get that right?
>
> ~ Erik,
> currently batting .034 in the bindings league ...
>
_______________________________________________
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