• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSTableView reloadData works just on init.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: NSTableView reloadData works just on init.
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Problem setting to-one relationship on NSManagedObject
  • Next by Date: MacBook with USB GPS dongle and Core Location
  • Previous by thread: Re: Problem setting to-one relationship on NSManagedObject
  • Next by thread: Re: NSTableView reloadData works just on init.
  • Index(es):
    • Date
    • Thread