• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: tableview problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: tableview problem


  • Subject: Re: tableview problem
  • From: Pandaa <email@hidden>
  • Date: Tue, 13 Apr 2004 13:17:24 +0200

Hello there,
I'm in a trouble

I need to load an XML plist into a tableView.
But I really can figure out the right way to do it.
Here is the code I use (as you can see, it's the code you can find in
Using Table View Article)

@implementation MostraDati

// Invoked by the table to find out how many rows of data are in the
data source.
- (int)numberOfRowsInTableView:(NSTableView *)tableView
{
NSString *filePath = [NSHomeDirectory()
stringByAppendingPathComponent:@"T_Rex/semola.txt"];
caricaDati = [NSMutableArray arrayWithContentsOfFile:filePath];
return [caricaDati count];
}

This is probably not such a great idea. Lazy loading of data is a good idea, but you need to check if you've already loaded your data from the file or you could end up loading it many times (and leak!) if the table view updates it's data. And, you probably want to retain caricaDati, as it seems to be an instance variable.

// Invoked by the table to retrieve data from the data source.
- (id)tableView:(NSTableView *)tableView
objectValueForTableColumn: (NSTableColumn *)tableColumn
row: (int)row
{
id theRecord, theValue;
NSParameterAssert(row >=0 && row < [caricaDati count]);

Paranoid. NSTableView will never send messages with out of bounds indexes unless you forget to tell it to reload data after destructive updates.

theRecord = [caricaDati objectAtIndex:row];

Now, here, the type of theRecord will depend on what was in the file you loaded caricaDati from.

Here you are presuming it's a dictionary:

theValue = [theRecord objectForKey:[tableColumn identifier]];


return theValue;
}


This is the error I get:
2004-04-13 12:13:07.891 Meeting_Manager[1025] *** -[NSCFString
objectForKey:]: selector not recognized

..while in fact it was a string!

2004-04-13 12:13:07.896 Meeting_Manager[1025] An uncaught exception was
raised

Maybe I should do something to the xml file before tableView tries to
load it?

Yes, before running your program you should make sure that it has the structure your program expects. Or make your program more intelligent.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . earth water fire air software - the five elements . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. email@hidden . . www.synapticpulse.net .
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >tableview problem (From: Simone Gabbriellini <email@hidden>)

  • Prev by Date: tableview problem
  • Next by Date: simple thread communication
  • Previous by thread: tableview problem
  • Next by thread: simple thread communication
  • Index(es):
    • Date
    • Thread