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 > Saving prefs in NSTableView

Saving prefs in NSTableView
Thread Tools
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
May 24, 2003, 04:13 PM
 
Hey guys,

I have an array that appears in a NSTableView (table).

The array is called items.

When it starts up it already has a list of things in it, but the user can also add and delete items. What I am wondering is, how to save the state of the NSTableView for when the user starts the app again?

Thanks!
Oliver
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
May 24, 2003, 05:04 PM
 
Write the array to your app's defaults. See the documentation on NSUserDefaults. (There's also a tutorial on Cocoa Dev Central about it.)
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Grizzled Veteran
Join Date: Jun 2002
Status: Offline
Reply With Quote
May 24, 2003, 05:43 PM
 
Is there any chance you could give me some sample code, I looked in the docs and at the tutorial but at am lost as to how I save this array into the prefs. Any help is appreciated!
Oliver
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
May 24, 2003, 06:25 PM
 
NSUserDefaults works basically like an NSMutableDictionary, except it has methods to add ints, floats and BOOLs as well as objects. So to put an array in your prefs, it's quite simple:
Code:
[[NSUserDefaults standardUserDefaults] setObject:items forKey:@"ItemsArray"];
(Last edited by Chuckit; May 24, 2003 at 07:28 PM. )
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
   
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 03:35 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