Re: NSTableView in-line editing
Re: NSTableView in-line editing
- Subject: Re: NSTableView in-line editing
- From: Jean-Daniel Dupas <email@hidden>
- Date: Tue, 25 Nov 2008 14:16:56 +0100
Le 25 nov. 08 à 13:52, 양승준 a écrit :
Hello,
I followed instructions from websites and apples' table view
programming guide to implement a table view that displays an
NSMutableArray of NSMutableDictionary's. Data show up in the table
view alright. But in-line editing is not working. I can double click
a cell, enter a number, but when I hit enter, the value changes back
to default. Do I have to do something to enable in-line editing? I
tried [[tableView tableColumnWithIdentifier:@"value"]
setEditable:YES]; But in vain. Here is my code. Many thanks!
@interface MyDocument : NSDocument
{
IBOutlet NSTableView * tableView;
NSMutableArray * aBuffer;
NSMutableDictionary * aPar1;
}
@implementation MyDocument
- (id)init
{
self = [super init];
if (self) {
aBuffer = [[NSMutableArray alloc] init];
aPar1 = [[NSMutableDictionary alloc] init];
[aPar1 setObject:@"aPar1" forKey:@"name"];
[aPar1 setObject:[NSNumber numberWithInt:256] forKey:@"value"];
[aBuffer addObject:aPar1];
}
}
- (int)numberOfRowsInTableView:(NSTableView *)aTableView
{
return [aBuffer count];
}
-(id)tableView:(NSTableView *)aTableView
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
id theRecord, theValue;
theRecord = [aBuffer objectAtIndex:rowIndex];
theValue = [theRecord objectForKey:[aTableColumn identifier]];
return theValue;
}
-(void)tableView:(NSTableView *)aTableView
setObjectValue:anObject
objectValueForTableColumn:(NSTableColumn *)aTableColumn
row:(int)rowIndex
{
id theRecord;
theRecord = [aBuffer objectAtIndex:rowIndex];
[theRecord setObject:anObject forKey:[aTableColumn identifier]];
return;
}
You have to implements the -
tableView:setObjectValue:forTableColumn:row: method too in your data
source.
This method will be invoke when a value change and it's up to you to
update your model. After that, the table view will automatically
retreive the value from your data source (invoking the
objectValueForTableColumn method).
_______________________________________________
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