objective c - Populating NSTableview from a mutable array -
I've been trying it for two days, and the dead is ending continuously.
Macro OS X has been done through coco programming of Aaron Hillegage, and has done all relevant studies related to the NSTEView and the Mutateable Areas and I am trying to amend them according to my needs. .
Although none of these data uses a array with objects in the form of a source, it seems that the tableview is used as a data source.
Any code or suggestion of Jonas Jangjan's " re-code" with the end of the Coco Front to display the results of
the results I know it should be simple, but I'm lost in the woods here.
I can populate the table by setting the array
It really is very Simple, once you understand him (definitely!). You can not use NSArray directly as a table source. You need to either create a custom object that implements or implements that protocol in some existing classes - usually the controller. If you use Xcode to create a standard document based application, then the document controller class - (it will be called MyDocument) is a good class to use.
You need to implement at least two of these methods:
- numberOfRowsInTableView: - tableView: objectValueForTableColumn: row:
< P> If you want a variable array whose value you want to use in a table view with a column, then something like the following should be done as a start: - numberOfRowsInTableView : (NSTableView *) aTableView {return [myMutableArray count]; } - tableView: (NSTableView *) aTableView objectValueForTableColumn: (NSTableColumn *) aTableColum Row: (NSInteger) rowIndex {return [myMutableArray objectAtIndex: rowIndex]; }
It can only be added to me with the place of NSArray myMutableArray
to add two methods as a class that self
and you can use an array as a data source.
However, with a temporary array, it is important that whenever you change it, you should know the table view that it has been changed, so you see the table Need to be sent if you have more than one column in your table view and you want to populate it with the properties of your object array, a trick that you can make for yourself can do. Let's say that objects in your array are examples of a class with two defined methods: And you want your table view to be a column for each, you can set the You can add a table of identification like column The combinations and values of these will automatically be populated. -reloadData .
- (NSString *) givenName; - (NSString *) Family name;
identifier
property of each column to the property name in person Displays that column and use something like the following:
- tableView: (NSTableView *) aTableView objectValueForTableColumn: (NSTableColumn *) aTableColum line: (NSInteger) rowIndex {person * items = [MyMutableArray objectAtIndex: line index]; Return [item value forKey: [tableColumn identifier]]; }
is replaced by valueForKey:
with valueForKeyPath:
and your individual square also has the following methods:
- (person *) mother; - (person *) Father; - (NSString *) Full name;
father.fullName
or mother.familyName
: // name and family name
Comments
Post a Comment