I have a method in my NSTableViewDelegate class to reload the data table from an external class:
- (void)reloadTable {
NSLog(@"reload data %@", table);
[table reloadData];
}
when I try to call this method from an external class, the table that is trying to be reloaded is null:
reload data (null)
I am calling this method with the following code in another class:
TableController *delegate = [[TableController alloc] init];
[delegate reloadTable];
Now, I would think this would be because I am init’ing a new instance of a table controller and calling the method on that instance of the table controller. So in my reloadTable method, I use self.table instead of table – this has the same results:
reload data (null)
In the .xib, dataSource and delegate are set to the TableController class. I suppose it should be noted that I am using a view-based tableview and I not using bindings. What am I missing?
EDIT: From these answers, it appears these issues may be caused because this class is just the datasource and delegate for the table view. Should I create a new class that is a ViewController for the TableView? Would I be correct in saying the class that exists would be the “Model” class and the new class I would create would be the “Controller” class in MVC?
EDIT 2: I created a TableViewController class and set the “view” outlet to my tableview in “Panel.xib”. In another class that I need to reload the table from, I do as follows:
TableViewController *tv = [[TableViewController alloc] initWithNibName:@"Panel" bundle:nil];
[tv.table reloadData];
No error is generated, but the table view does not reload.
You need to use
-initWithNibName:bundle:to create your ViewController.