0

我有一个带有“旧”Tabbarcontroller 和 MainWindow.xib 的应用程序。我必须删除 tabbarcontroller 逻辑来转换应用程序并制作“左侧菜单”类型,如 facebook。我有一个问题,我已经用 tableviewcontroller 创建了左侧菜单,我可以打开、关闭和正确推送我的控制器......现在我想为每个导航控制器插入一个不同的自定义导航栏类​​(在旧版本的app 每个导航控制器都有他的自定义导航类来更改与活动视图控制器相关的 che 图像)。这是我在左侧菜单中一行的 tableview didselect 方法中使用的代码:

 if (indexPath.row==1) {

    DemoViewController *demoController = [[DemoViewController alloc] init];
    UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
    [navigationController setValue:[[CustomNavigationBar alloc]init] forKeyPath:@"navigationBar"];
    NSArray *controllers = [NSArray arrayWithObject:demoController];
    navigationController.viewControllers = controllers;
    [self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
} 

此代码正确管理幻灯片并正确加载 MFSideMenu 内的视图控制器。自定义导航栏类​​已分配但无法正常工作:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{

这个方法永远不会被调用,也许 MFSideMenu 覆盖了 uinavigationcontroller 委托?我怎样才能使这个导航控制器委托方法再次“活跃”?

4

1 回答 1

1

找到了解决方案,这段代码:

      DemoViewController *demoController = [[DemoViewController alloc] init];
    UINavigationController *navigationController = self.menuContainerViewController.centerViewController;

    CustomNavigationBar *navClass=[[CustomNavigationBar alloc]init];
    [navigationController setValue:navClass forKeyPath:@"navigationBar"];
    [navigationController setDelegate:navClass];

    NSArray *controllers = [NSArray arrayWithObject:demoController];
    navigationController.viewControllers = controllers;
    [self.menuContainerViewController setMenuState:MFSideMenuStateClosed];

代替:

DemoViewController *demoController = [[DemoViewController alloc] init];
UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
[navigationController setValue:[[CustomNavigationBar alloc]init] forKeyPath:@"navigationBar"];
NSArray *controllers = [NSArray arrayWithObject:demoController];
navigationController.viewControllers = controllers;
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];

通过这种方式,代表被正确分配......

于 2013-09-17T15:33:38.237 回答