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

0119374

Cancelled
Original poster
May 17, 2007
8
0
Hi to all,

I want to show in NSTableview some info.

I see in apple developer documents that it shows using bindings and NSArrayController but i don't get it work.

This is my situation :

@interface PersonsList : NSObject
{
NSMutableArray *persons;
NSString *city
}

@interface Person : NSObject
{
NSString *name;
NSString *zipCode;
NSString *address;
}

NSMutableArray persons is an array of person objects.

I want to show in NSTableview the info of Person Object i have in PersonsList NSMutableArray persons.

Thanks.
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
If you stick with what you've got you need to write a bunch of methods like
Code:
-(NSString*) name;
{
    return name;
}

-(void) setName:(NSString*) newName;
{
   [newName retain];
   [name release];
   name=newName;
}
You need to do that for every public variable that isn't an array.

OR

You could do like the examples and change is so you have one variable that's a mutable dictionary then you only need to write one pair of properties/setProperties methods.

Of course in Objective-C 2.0 you won't have to write all these setters/getters as then we'll have 'properties'. Sadly that will be Leopard only....
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
Can't you create an NSArrayController and use that like you do for CoreData?

TBH though the table displaying methods are pretty easy, you just implement

Code:
-(int)numberOfRowsInTableView:(NSTableView *)aTableView;
and
Code:
-(id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
		   row:(int)row;
In your application controller, then you point the table's "data source" connection to your application controller.

Then you just use the reloadData method in NSTableView to change what gets displayed in the table.
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
Yeah but he was asking about using bindings. You could use the datasource methods and in some cases they're still the best option but that wouldn't be using bindings.
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
Yeah but he was asking about using bindings. You could use the datasource methods and in some cases they're still the best option but that wouldn't be using bindings.

I know, I think people get obsessed with bindings, they aren't always the best way ;).
 

0119374

Cancelled
Original poster
May 17, 2007
8
0
Can't you create an NSArrayController and use that like you do for CoreData?

TBH though the table displaying methods are pretty easy, you just implement

Code:
-(int)numberOfRowsInTableView:(NSTableView *)aTableView;
and
Code:
-(id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
		   row:(int)row;
In your application controller, then you point the table's "data source" connection to your application controller.

Then you just use the reloadData method in NSTableView to change what gets displayed in the table.

Thanks , with this i can get NSMutableArray *persons from PersonsList into NSTableView.

But how to get it work with bindings ?.

-(NSString*) name;
{
return name;
}

-(void) setName:(NSString*) newName;
{
[newName retain];
[name release];
name=newName;
}

I do this in all objects that isn't an array , but i can't get it work.
 

Eraserhead

macrumors G4
Nov 3, 2005
10,434
12,250
UK
Thanks , with this i can get NSMutableArray *persons from PersonsList into NSTableView.

Good, so just use this ;).

EDIT: As a general tip about programming: If it works, and at a decent speed on the target system it is fine and leave it and work on the next problem, time is finite after all.
 

slooksterPSV

macrumors 68040
Apr 17, 2004
3,544
306
Nowheresville
In interface builder, you bind the columns of the objects with the array controller and the value the column is supposed to hold. E.g. if your NSArrayController was called Persons, you'd do the bindings for the column (lets say of name) as it's going to bind to Persons; then in the text field it'sll say value and you type in name On one of those sites it shows you how to do it, with pictures and that.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.