Hi all. I'm starting to develop in cocoa and have this problem that can't figure out by myself.
I have a class with a NSMutableArray list. In the interface have a bunch of NSTextFields, an "Add Item" button and a table to display added items.
In the controller, I had added the methods to create a new item and add it to the array. Also, I'd set the table datasource to the controller and added the two methods to retrieve the item count and to return a the value for a given row and column.
The problem is that when I want to retrieve the items in the
- (id) tableView: (NSTableView *)tv objectValueForTableColumn : row
the item from the array list haves:
NSString *name
NSString *brand
float quantity
float price
NSString *category
but, when i retrieve it from the list to return the value of the row/column, the item haves all it's attributes but the tipe is NSRectSet.
does anybody know what could be wrong?
here is the code:
ListController.m:
thanks in advance!
I have a class with a NSMutableArray list. In the interface have a bunch of NSTextFields, an "Add Item" button and a table to display added items.
In the controller, I had added the methods to create a new item and add it to the array. Also, I'd set the table datasource to the controller and added the two methods to retrieve the item count and to return a the value for a given row and column.
The problem is that when I want to retrieve the items in the
- (id) tableView: (NSTableView *)tv objectValueForTableColumn : row
the item from the array list haves:
NSString *name
NSString *brand
float quantity
float price
NSString *category
but, when i retrieve it from the list to return the value of the row/column, the item haves all it's attributes but the tipe is NSRectSet.
does anybody know what could be wrong?
here is the code:
ListController.m:
Code:
- (IBAction)addItem:(id)sender{
ListItem *item;
item = [[ListItem alloc] init];
[item setItemName: [nameField stringValue]];
[item setBrand:[brandField stringValue]];
[item setCategory:[categoryField stringValue]];
[item setQty:[qtyField floatValue]];
[item setPrice:[priceField floatValue]];
[shopList addItem: item];
[table setDataSource: self];
[table reloadData];
// clear text fields
[nameField setStringValue:@""];
[brandField setStringValue:@""];
[categoryField setStringValue:@""];
[qtyField setStringValue:@""];
[priceField setStringValue:@""];
}
- (int)numberOfRowsInTableView:(NSTableView *)tv {
return [[shopList items] count];
}
- (id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn *)tc row:(int)row {
ListItem *item = [shopList objectAtIndex:row];
NSString *returnValue;
if ([[tc identifier] isEqualToString: @"idCol"]){
returnValue = [NSString stringWithFormat:@"%i", row];
}
else if ([[tc identifier] isEqualToString:@"Category"]){
returnValue = [item category];
}
else if ([[tc identifier] isEqualToString:@"Name"]){
returnValue = [item itemName];
}
else if ([[tc identifier] isEqualToString:@"Brand"]){
returnValue = [item brand];
}
else if ([[tc identifier] isEqualToString:@"Quantity"]){
returnValue = [NSString stringWithFormat:@"%1.2f", [item qty]];
}
else if ([[tc identifier] isEqualToString:@"Price"]){
returnValue = [NSString stringWithFormat:@"%1.2f", [item price]];
}
return returnValue;
}
thanks in advance!