NSTableView update basics
NSTableView update basics
- Subject: NSTableView update basics
- From: Erik Stainsby <email@hidden>
- Date: Thu, 08 Mar 2012 21:42:06 -0800
I have a tableView which will accept one new row and updates to that row succeed. Subsequent application of the same process does add new rowData dictionary objects to the tableData model (NSMutableArray) but the tableView will not display these additions.
A button on the UI is wired up to - (IBAction) addTableItem:(id)sender; and pops in the first row just fine. NSLog() messages have revealed that additional clicks on the button add new rows to the tableData array, but the UI does not respond to these events.
I'm pretty sure I'm missing something pretty basic here.
@interface MyClass : NSViewController < NSTableViewDataSource, NSTableViewDelegate >
@property (retain) IBOutlet NSTableView * tableView;
@property (retain) IBOutlet NSMutableArray * tableData;
- (IBAction) addTableItem:(id)sender;
@end
@implementation MyClass
@synthesize tableView;
@synthesize tableData;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
tableData = [NSMutableArray array];
}
return self;
}
- (NSInteger) numberOfRowsInTableView:(NSTableView *)tableView {
return [tableData count] || 0;
}
- (id) tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
NSDictionary * rowData = [tableData objectAtIndex:row];
return [rowData valueForKey:[tableColumn identifier]];
}
- (void)tableView:(NSTableView *)aTableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex {
NSMutableDictionary * rowData = [[tableData objectAtIndex:rowIndex] mutableCopy];
[rowData setValue:anObject forKey:[aTableColumn identifier]];
[tableData replaceObjectAtIndex:rowIndex withObject:rowData];
[tableView reloadData];
}
- (IBAction) addTableItem:(id)sender {
[tableData addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"prop",@"property",@"val",@"value",nil]];
[tableView reloadData];
}
@end
Erik Stainsby
email@hidden
-------------------------------------
Consistently place constants on the LHS of an expression: you cannot accidentally assign when you meant to compare.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden