Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh a View Controller

In my app delegate, I have this method that gets stubbed out automatically, to do something when a view controller gets selected.

If the type of the viewController is SavedViewController, then it's a UITableView subclass, and I would like to refresh the table. However, this code doesn't work:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
  if([viewController isKindOfClass: [SavedViewController class]]) {
    [viewController.tableView reloadData];
  }
}

The error I get is "request for tableView is something not a structure or union. Within the SavedViewController class, I can do this just fine:

[self.tableView reloadData];

So, what am I doing wrong in my function?

like image 447
Andrew Johnson Avatar asked Jul 21 '26 07:07

Andrew Johnson


1 Answers

Switch this line:

[viewController.tableView reloadData];

To this:

[[(SavedViewController *)viewController tableView] reloadData];
like image 173
Dan Lorenc Avatar answered Jul 24 '26 00:07

Dan Lorenc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!