当tableview位于子视图ViewCon的子视图中时,如何重新加载数据

时间:2014-05-20 17:31:24

标签: ios objective-c uitableview uiviewcontroller

我有一个ViewController,其中tableView已添加为子视图,然后嵌入UINavigationController,然后作为子视图添加到我的RootViewController中我的ViewDidLoadRootViewConroller)。

frontController = [[UIViewController alloc] init];
frontController.view.backgroundColor = [UIColor blackColor];
[frontController.view addSubview:self.tableView];

... ///

self.navBar = [[UINavigationController alloc] initWithRootViewController:self.frontController];

//finally add the Top UIViewController
 self.contentViewController = self.navBar;


/// Move to new view when cell is touched
     DetailsTwo *my_detailViewController = [[DetailsTwo alloc] initWithNibName:@"DetailsTwo" bundle:[NSBundle mainBundle]];

            [self.navBar pushViewController:my_detailViewController animated:YES];

我的问题:我如何[tableView reloadData]表格视图(当我从navBar的后退按钮返回视图时)?

为什么ViewWillAppearViewDidAppear都没有被调用(概念上我错过了什么)?

希望有意义,谢谢你。

1 个答案:

答案 0 :(得分:0)

@jeffamaphone - 让我走上正轨:(希望这有助于其他人)

//.h
@interface RootViewController : UIViewController <UINavigationControllerDelegate> {
    UINavigationController *navController;
}

//.m
Then implement these two methods:

- (void)navigationController:(UINavigationController *)navigationController 
    willShowViewController:(UIViewController *)viewController animated:(BOOL)animated 
{
    [viewController viewWillAppear:animated];
}

- (void)navigationController:(UINavigationController *)navigationController 
    didShowViewController:(UIViewController *)viewController animated:(BOOL)animated 
{
    [viewController viewDidAppear:animated];
}

*****确保将根视图控制器设置为导航控制器的委托。现在只要从堆栈中推送/弹出控制器,就会调用viewWillAppear / viewDidAppear。