如何从UITabBarViewController调用sub-tableVIew方法

时间:2015-03-06 10:41:39

标签: ios objective-c uitableview uitabbarcontroller

- (void)tabBarController:(UITabBarViewController *)tabBarController   didSelectViewController:(UIViewController *)viewController {
NSLog(@"selected %lu",(unsigned long)tabBarController.selectedIndex);
   if (tabBarController.selectedIndex == 0) {
  //call refresh() in PlayerTableViewController 
   } else {
    // ...
   }
}

以下是UITabBarViewController

在第4行中,我想调用一个名为refresh()的方法来更新PlayerTableViewController中的数据。我该如何实现它? 谢谢 enter image description here

1 个答案:

答案 0 :(得分:1)

- (void)tabBarController:(UITabBarViewController *)tabBarController       didSelectViewController:(UIViewController *)viewController {
NSLog(@"selected %lu",(unsigned long)tabBarController.selectedIndex);
 if (tabBarController.selectedIndex == 0) {
 //call refresh() in PlayerTableViewController 
 UINavigationController *navController = (UINavigationController *)tabBarController.selectedViewController;
 PlayerTableViewController *playerTableVC =(PlayerTableViewController *)  [navController.viewControllers firstObject];
 [playerTableVC.tableView reloadData];



} else {
// ...
}
}