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 > Newbie question: NSNotification for NSTableView reloadData

Newbie question: NSNotification for NSTableView reloadData
Thread Tools
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Oct 31, 2002, 12:42 AM
 
Hi,

I was wondering how I could know each time that my tableview reloads the data, or any value in the tableview changes. Each time this happens I want to total all of the int values in a column and display it in a text field.

Can someone help me with the most efficient way to do this? If I should use an NSNotificationCenter, how would I set this up?

Thanks for being patient while I am learning.
     
Mac Elite
Join Date: Feb 2001
Location: adrift in a sea of decadent luxury and meaningless sex
Status: Offline
Reply With Quote
Oct 31, 2002, 02:35 AM
 
unless I'm missing something, you have to implement the method tableView:objectValueForTableColumn:row:, etc, in your table data source, and this method will be called by the tableView once for every cell on every reload. So you could put your totaling code in this function, but keep in mind that it will be called very very frequently, especially if your table view can be resized.

I suggest totaling when the table data changes, which happens when the table calls tableView:setObject:forTableColumn:row: in your table data source.

These method names are just off the top of my head though
blackmail is such an ugly word. I prefer extortion. the X makes it sound cool
     
Professional Poster
Join Date: Sep 1999
Location: Ottawa, ON, Canada
Status: Offline
Reply With Quote
Oct 31, 2002, 08:32 AM
 
Originally posted by lucylawless:
unless I'm missing something, you have to implement the method tableView:objectValueForTableColumn:row:, etc, in your table data source, and this method will be called by the tableView once for every cell on every reload.
Tee hee, they really should turn off smilies in this forum.

For example,
[myMethodsadParam + 1) andThisotherSadParam + 2)];
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Oct 31, 2002, 10:00 AM
 
So I guess what I will do is put in my total method in the setObjectValueForLocation delegate method.

I wonder if this will slow things down. How much faster is Obj-C verse Java for going through loops and such?
     
Senior User
Join Date: Jun 2001
Location: Merry Land
Status: Offline
Reply With Quote
Nov 4, 2002, 09:54 AM
 
Originally posted by hayesk:


Tee hee, they really should turn off smilies in this forum. :D

For example,
[myMethod:(sadParam + 1) andThis:(otherSadParam + 2)];
Guess you missed the "Disable smilies in this post" checkbox, huh? ;)
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Nov 4, 2002, 10:46 AM
 
Lets say I wanted to use NSNoticiations and NSNotificationCenter. How would I go about doing this? I thought in my -(id)init method or -(id)awakeFromNib I could put in a piece of code that says, "look for a notification that is called 'SomethingChangedNotification'". I then thought that whenever a certain function gets called I could post a notification called "SomethingChangedNotification". Is this the more or less correct wat to go about doing this?
     
Forum Regular
Join Date: Aug 2000
Location: UK
Status: Offline
Reply With Quote
Nov 4, 2002, 05:35 PM
 
I think you're going about this the wrong way. Instead of calling [yourTable reloadData] & trying to add code to the table datasource callbacks, create a method in your controller class eg. [myController reloadData].

Then write this method so that it updates your totals and then calls [yourTable reloadData] at the end.
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Nov 4, 2002, 07:44 PM
 
Originally posted by calumr:
I think you're going about this the wrong way. Instead of calling [yourTable reloadData] & trying to add code to the table datasource callbacks, create a method in your controller class eg. [myController reloadData].

Then write this method so that it updates your totals and then calls [yourTable reloadData] at the end.
I could do this, but then I would need to call the method [myController reloadData] in a lot of places in my model class. If I use a notification, maybe it would be easier?
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Nov 4, 2002, 08:35 PM
 
Originally posted by macrophyllum:


I could do this, but then I would need to call the method [myController reloadData] in a lot of places in my model class. If I use a notification, maybe it would be easier?
There's only two ways to do this: implement reloadData in your controller class and have that method call reloadData on your tableView and keep track of any recalculations you want, or subclass NSTableView and override the implementation of reloadData (making sure to class [super reloadData]) and have it post a notification each time it happens. I think writing your own reloadData method would be easier, and it would be trivial to change in your code by simply doing a find replace:

Find: [myTable reloadData]
Replace: [self reloadData]

HTH,
Matt
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Nov 5, 2002, 12:28 AM
 
Originally posted by Ghoser777:


There's only two ways to do this: implement reloadData in your controller class and have that method call reloadData on your tableView and keep track of any recalculations you want, or subclass NSTableView and override the implementation of reloadData (making sure to class [super reloadData]) and have it post a notification each time it happens. I think writing your own reloadData method would be easier, and it would be trivial to change in your code by simply doing a find replace:

Find: [myTable reloadData]
Replace: [self reloadData]

HTH,
Matt
This worked well. Thanks!
     
   
Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:16 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2