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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to