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
erik.stain...@roaringsky.ca
-------------------------------------
Consistently place constants on the LHS of an expression: you cannot 
accidentally assign when you meant to compare.





_______________________________________________

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

This email sent to arch...@mail-archive.com

Reply via email to