Hi Coolio, and welcome to the Dev Forum!
Coolio098 wrote:
... under viewWillAppear and viewDidAppear, self.tableView shows up as null. When I call the reloadData from a button it shows that self.tableView has a value.
I tried various nib configurations, but was unable to reproduce the behavior you're seeing. I seem to remember seeing it in the past, though--just can't remember how I did it. I thought the behavior might have been related to setting the 'view' property of the controller to the UIView object which was the superview of the table view (as in your diagram), but when I tried that today, all I got was: 'NSInternalInconsistencyException', reason: '-[UITableViewController loadView] loaded the "MyController" nib but didn't get a UITableView.'
Any clues as to why this might be happening?
It might be related to the extra view in your nib. I'm also wondering if you implemented loadView (instead of, or in addition to viewDidLoad). That's the best I can do without reproducing the behavior. Btw, do you need that extra view? E.g. does it have other subviews besides the table view? If not, I would recommend taking it out of the nib. whether that fixes the current problem or not.
Anyway, communicating with your table view from viewDidAppear: should be easy, if you'll settle for a workaround instead of an explanation. If the controller's 'view' outlet is connected to the table view in the nib (based on the exception I'm seeing, there's no other choice for a subclass of UITableView), just send your messages to that address. E.g.:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@"%s: view=%@ tableView=%@", _func_, self.view, self.tableView);
[(UITableViewController*)self.view reloadData];
}
Else, if you somehow managed to connect the 'view' outlet to the table view's superview without getting an exception, try something like this:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLog(@"%s: view=%@ tableView=%@", _func_, self.view, self.tableView);
// try afterDelay:.001 etc., if 0.0 doesn't work
[self performSelector:@selector(reloadTableViewData) withObject:nil afterDelay:0.0];
}
- (void)reloadTableViewData {
NSLog(@"%s: view=%@ tableView=%@", _func_, self.view, self.tableView);
[self.tableView reloadData];
}
If none of the above is helpful, please post the class files for your controller, along with more details about the controller's nib (e.g. the exact connections). It might also help to know which template you started with, and if you touched MainWindow.nib. Lastly, please include the Console log messages produced by running one of the above code examples.
- Ray