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 > Property List for NSTableView

Property List for NSTableView
Thread Tools
Mac Elite
Join Date: May 2002
Location: New York City
Status: Offline
Reply With Quote
Mar 27, 2003, 04:11 PM
 
This may be a stupid question, but:

I have a table in an application I'm making which would
require large amounts of information to be stored in it (100's, in fact).

So the question is - how would I go about using a Property List
(.plist) dictionary to store the various values?

I already have a data source setup (and the table works fine),
but I want to use a plist.


Any help would be appreciated.
     
Forum Regular
Join Date: Aug 2000
Location: UK
Status: Offline
Reply With Quote
Mar 27, 2003, 04:58 PM
 


+[NSArray arrayWithContentsOfFile:]

and

-[NSArray writeToFile:atomically:]

These read/write an array to/from a .plist file. All you need to do is put your data in an NSArray (providing you haven't done so already).

Make sure that the only items in the array (and the items they contain in) are either NSStrings, NSNumbers, NSURLs, NSDictionarys, other NSArrays or instances of NSData (there may be more that I've forgotten). You can't put other classes (like NSView, or your own custom classes) in an an NSArray if you want to store it in a .plist file.

It's all here:

file://localhost/Developer/Documenta...sts/index.html
     
zachs  (op)
Mac Elite
Join Date: May 2002
Location: New York City
Status: Offline
Reply With Quote
Mar 27, 2003, 05:19 PM
 
OK, the table is basically two columns, one with numbers,
the other with descriptions (of emoticons).

So, my code is:

- (id)init
{
[super init];

Smile *name = [[Smile alloc] init];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Smilies" ofType:@"plist"];
NSMutableArray *smilies = [NSMutableArray arrayWithContentsOfFile:path]; //reading the plist



[name setURL:@"412"]; //the first column
[name setName:@"Big Grin"]; //the second

items = [[NSMutableArray alloc] init];
[items addObject:name];
[name release];
return self;
}
So how would I insert a value from the plist
into, say the first column?

Sorry, I'm new to doing this.
     
Senior User
Join Date: Dec 2001
Status: Offline
Reply With Quote
Mar 29, 2003, 03:40 PM
 
Originally posted by zachs:
...So how would I insert a value...
You don't. NSTableView and friends ask *you* what values to display. You can tell them that new data is available by with -[NSTableView reloadData]. You should really read Apple's docs on NSTableView, they explain it very clearly. In Cocoa, you will *never* say something like "insert this data before row 8", but rather the NSTableView will determine what rows it is currently displaying, and ask its data source object for the data to display in those rows.
"Think Different. Like The Rest Of Us."

iBook G4/1.2GHz | 1.25GB | 60GB | Mac OS X 10.4.2
Athlon XP 2500+/1.83GHz | 1GB PC3200 | 120GB | Windows XP
     
   
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 08:57 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