Thanks for the advice!
My data source is indeed kind of a M&C and I was actually very close to an attempt at subclassing the tableView and making it a MVC all in one :-) (I don't remember what divine intervention stopped me :-) ) _______________________________________________________________________ Valentin Dan, Software Engineer Direct: +1 905 886 1833 ext.3047 Email: valentin....@masstech.com Office: +40 356-710158 Masstech Group Inc. Fax: +40 256-220912 http://www.masstechgroup.com THIS MESSAGE IS INTENDED ONLY FOR THE ADDRESSEE. IT MAY CONTAIN PRIVILEGED OR CONFIDENTIAL INFORMATION.ANY UNAUTHORIZED DISCLOSURE IS STRICTLY PROHIBITED.IF YOU HAVE RECEIVED THIS MESSAGE IN ERROR, PLEASE NOTIFY US IMMEDIATELY SO THAT WE MAY CORRECT THE RECORDS. PLEASE THEN DELETE THE ORIGINAL MESSAGE. THANK YOU. -----Original Message----- From: Graham Cox [mailto:graham....@bigpond.com] Sent: Friday, February 06, 2009 5:37 PM To: Valentin Dan Cc: Cocoa Developers Subject: Re: NSTableView and DataSource problem Here's a minimalistic datasource that works in many common situations: - (int) numberOfRowsInTableView:(NSTableView*) aTableView { return [myDataArray count]; } - (id) tableView:(NSTableView*) aTableView objectValueForTableColumn: (NSTableColumn*) aTableColumn row:(int) rowIndex { return [[myDataArray objectAtIndex:rowIndex] valueForKey: [aTableColumn identifier]]; } This allows you to set up the actual properties that the table displays in IB rather than in code, by setting the table column's 'identifier' string to the property key of interest. Normally the datasource is implemented by a controller object, which will also keep track of the data model it controls (myDataArray in the above example). To update the table, you just change the data in the array as you wish then call -reloadData on the table. Sounds like you're overthinking this. Proper understanding of the model-view-controller (MVC) pattern will help - the data source is firmly in the 'C' layer, and not the 'M' layer as you seem to be hinting. hope this is helpful, --Graham On 7 Feb 2009, at 2:15 am, Graham Cox wrote: > > On 7 Feb 2009, at 2:10 am, Valentin Dan wrote: > >> Anyway, what's the proper method for updating the data for the >> list ? I >> need to change all the data. >> >> >> >> Currently I'm setting the tableView's data source to "nil", I'm >> releasing the old dataSource, creating a new one (with the new items) >> then setting a the table's dataSource to the new one... is that >> close ? >> :-) > > > Not even. > > The datasource is a fairly passive entity, sitting waiting to be > asked by the table to give it content. If the data changes you > simply call [table reloadData]; and the datasource will be called > again as needed to return the new data. > > Swapping out the datasource is never needed. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com