Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Chirone

macrumors 6502
Original poster
Mar 2, 2009
279
0
NZ
...so i'm having trouble trying to add values from an array to an NSTableView

i could use bindings but the code doesn't allow for such things to exist. that and i even if i could get the key i wouldn't know how to get the value i want because it's a 2D array i'm reading off

anyway, what's the method that will add a string value to an nstable?
sounds like it should be simple... just like a addValue:atColumn:atRow method...

i've searched the internet for adding values to nstableviews but nothing useful comes up...

ok, nevermind, it'd not actually possible says the documentation. guess i will have to try the popup button instead
 
I believe you are thinking about it the wrong way. Rather than the table view holding the data you need to provide a delegate that the tableview will ask for data when it needs it.

Hope that helps - the docs should take you further - I don't have them to hand atm
 
yeah, i looked at the delegates but didn't see one, maybe i still managed to miss the correct delegate

i found that you can get the table to read it's data off a so-called dataSource, so maybe, next time i'll do that

but for now the popup button achieves the outcome that i wanted, and for what it's doing it was probably a better choice
 
The way it works is that you declare the class you're using to manage the data for that table, the "data source" of that table (by wiring it up in IB). then you need to implement 2 methods if it's a non-editable table to something similar to this:

Code:
- (int) numberOfRowsInTableView: (NSTableView *) aTableView
{
	return [anArrayOfData count];
}

- (id) tableView: (NSTableView *) aTableView
objectValueForTableColumn: (NSTableColumn *) aTableColumn
			 row: (int) rowIndex
{
	NSString *s	 = [anArrayOfData objectAtIndex: rowIndex];
	return s;
}

The table decides when it's time to call those methods (your data source class is it's helper).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.