Hi, I have a singleton class that manages a tableView (and provides the datasource).
Now I would like to update this tableView from another class. Since the class that manages the tableView is a singleton I don't have to initiate a new instance of that class. So I thought there should be no problem to change the content of the datasource for the tableView and then update the tableView with [table reloadData]; from a different class. I indeed can change the datasource (a mutable Array) but the reloadData command doesn't update the content of the table in the window. What am I doing wrong? Why has the [table reloadData]; command in the updateView-method no effect on the table when it is evoked from a different class (see updateTest.h)? I tried to isolate the code from my main project; This test-project contains three classes: The one that is connected to the preferences.xib providing the datasource for the tableView – tableViewController.h the tableview_testAppDelegate.h and a class that tries to change the data datasource and tries to send a request to update the tableView – updateTest.h I have a preference.xib file with a tableView that is connected to the preference-object (provides the datasource). I would be really glad for any help! I hope someone can understand my problem ... I am still a bloody beginner. // Here the tableViewController gets invoked - a window with a table appears showing the content of an array with two dictionaries (the array is called content) tableview_testAppDelegate.h ———————————————————— #import <Cocoa/Cocoa.h> #import "tableViewController.h" @interface tableview_testAppDelegate : NSObject <NSApplicationDelegate> { tableViewController *test; } @end tableview_testAppDelegate.m ———————————————————— #import "tableview_testAppDelegate.h" #import "tableViewController.h" #import "updateTest.h" @implementation tableview_testAppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { test = [tableViewController sharedPrefsWindowController]; [test showWindow:self]; updateTest *deleteEntry; deleteEntry = [[updateTest alloc] init]; } @end // Here the tableViewController gets the an updateView-command – one element of the array gets deleted and the tableView gets an update command (with no effect) updateTest.h ———————————————————— #import <Cocoa/Cocoa.h> #import "tableViewController.h" @interface updateTest : NSObject { tableViewController *update; } @end updateTest.m ———————————————————— #import "updateTest.h" #import "tableViewController.h" @implementation updateTest - (id) init { update = [tableViewController sharedPrefsWindowController]; [update updateView]; return self; } @end tableViewController.h ———————————————————— #import <Cocoa/Cocoa.h> @interface tableViewController : NSWindowController <NSToolbarDelegate> { IBOutlet NSTableView *table; NSMutableArray *content; } @property (assign) IBOutlet NSWindow *window; + (tableViewController *)sharedPrefsWindowController; + (NSString *)nibName; - (int)numberOfRowsInTableView:(NSTableView *)tableView; - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row; - (IBAction)tableViewSelected:(id)sender; - (void)updateView; @end tableViewController.m ———————————————————— #import "tableViewController.h" static tableViewController *_sharedPrefsWindowController = nil; @implementation tableViewController + (tableViewController *)sharedPrefsWindowController { if (!_sharedPrefsWindowController) { _sharedPrefsWindowController = [[self alloc] initWithWindowNibName:[self nibName]]; } return _sharedPrefsWindowController; } - (void) dealloc { [super dealloc]; } + (NSString *)nibName { return @"preferences"; } -(void)awakeFromNib { NSDictionary *dict; dict = [NSDictionary dictionaryWithObjectsAndKeys: @"test", @"title", nil]; content = [[NSMutableArray alloc] init]; [content addObject:dict]; [content addObject:dict]; NSLog(@"content %@", content); } - (int)numberOfRowsInTableView:(NSTableView *)tableView { return [content count]; } - (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row { return [[content objectAtIndex:row] valueForKey:@"title"]; } - (IBAction)tableViewSelected:(id)sender { char row; row = [sender selectedRow]; NSIndexSet * selected; selected = [[NSIndexSet alloc] init]; selected = [sender selectedRowIndexes]; } - (void)updateView { [content removeObjectAtIndex:0]; [table reloadData]; NSLog(@"updated content %@", content); } @end _______________________________________________ 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 arch...@mail-archive.com