views:

706

answers:

3

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?

A: 

try casting to a uitableviewcontroller

ennuikiller
+2  A: 

Switch this line:

[viewController.tableView reloadData];

To this:

[[(SavedViewController *)viewController tableView] reloadData];
Dan Lorenc
I think you are right, but after putting in some log statements, I don't think the function is ever getting called. This method must not be for what I think it's for?
Andrew Johnson
I figured out the last bit... needed to set the delegate of the tabBarController.
Andrew Johnson
A: 

Hey Guys,

I try to do the same thing. I am trying to refresh my table But I am not able to do it My code snippet is

  • (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController )viewController { NSLog(@"tab changed %@",viewController.tabBarItem.title ); if([viewController.tabBarItem.title isEqualToString:@"RESULTS"]) { NSLog(@"resultsviewcontroller"); [[(ResultViewController)viewController tableView] reloadData]; } } The above function is in my appdelegate I have the Tableview in class that is inherited by ResultViewController.

The error I get 2009-07-29 10:28:06.198 GetFugu3[485:207] * -[UINavigationController tableView]: unrecognized selector sent to instance 0x11c400 2009-07-29 10:28:06.206 GetFugu3[485:207] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UINavigationController tableView]: unrecognized selector sent to instance 0x11c400' 2009-07-29 10:28:06.220 GetFugu3[485:207] Stack: ( 808001701, 805397928, 808005509, 807501935, 807464352, 9273, 816172608, 807759323, 815194328, 815194176, 817067000, 807759323, 815194328, 815194176, 815194120, 815193184, 815192640, 817055280, 807759323, 815194328, 815194176, 815194120, 815193184, 815427236, 815423708, 815420524, 814968388, 814966908, 839149932, 807750263, 807747947, 839144100, 814678908, 814672532, 8381, 8244 ) terminate called after throwing an instance of 'NSException'

Sowri