NSTableView reloadData works just on init.
NSTableView reloadData works just on init.
- Subject: NSTableView reloadData works just on init.
- From: Alberto Piu <email@hidden>
- Date: Sat, 5 Dec 2009 13:22:12 +0100
Hi all,
I'm writing on this mailing list because I can't get an NSTableView to
display data.
I have a NSTableView in my xib, connected to a NSObject controller.
dataSource is my controller, and the IBOutlet is correctly connected
to the NSTableView.
This is my header
//
// ShortcutsTableController.h
//
#import <Cocoa/Cocoa.h>
@interface ShortcutsTableController : NSObject
<NSTableViewDataSource> {
IBOutlet NSTableView *shortcutsTable;
NSMutableArray *shortcutsList;
}
@property (assign) IBOutlet NSTableView *shortcutsTable;
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:
(NSTableColumn *)tableColumn row:(int)row;
- (void)addItem:(NSString *)name :(NSString *)shortcut :(NSString *)
action;
- (void)reloadData;
@end
And this is my implementation file.
//
// ShortcutsTableController.m
//
#import "ShortcutsTableController.h"
@implementation ShortcutsTableController
@synthesize shortcutsTable;
- (id)init
{
self = [super init];
if (self != nil) {
shortcutsList = [[NSMutableArray alloc] init];
shortcutsTable = [[NSTableView alloc] init];
[shortcutsTable setDataSource:self];
[self reloadData];
}
return self;
}
- (void)addItem:(NSString *)name :(NSString *)shortcut :(NSString *)
action {
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:
name, @"nameColumn",
shortcut, @"shortcutColumn",
action, @"actionColumn", nil];
[shortcutsList addObject:dict];
NSLog(@"%@", shortcutsTable);
NSLog(@"%@", shortcutsList);
[self reloadData];
}
- (void)reloadData {
[shortcutsTable reloadData];
}
-(NSInteger) numberOfRowsInTableView: (NSTableView *) tableView {
return [shortcutsList count];
}
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:
(NSTableColumn *)tableColumn row:(int)row {
if (row != -1)
return [[shortcutsList objectAtIndex:row] objectForKey:
[tableColumn identifier]];
return nil;
}
@end
I can't display data in this TableView using addItem method. If I call
addItem from the init method all goes as expected, otherwise the
tableView is not updated. I don't know what's my mistake.
You know what's going wrong?
If yes, please help me. Your help would be very appreciated.
Sweet day,
—Albé_______________________________________________
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