我有一个带有“旧”Tabbarcontroller和MainWindow.xib的应用程序。我必须删除tabbarcontroller逻辑来转换应用程序并制作一个“左侧菜单”类型,如facebook。我有一个问题,我有alredy用tableviewcontroller创建左侧menù我可以打开,关闭并正确推送我的控制器...现在我想插入一个不同的customnavigation bar类每个导航控制器(在旧版本的app每个导航控制器都有自定义导航类来改变与活动viewcontroller相关的che图像。这是我在tableview中使用的代码在左侧菜单中选择了一行的方法:
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中的viewcontroller。自定义导航栏类已分配但无法正常工作:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
永远不会调用此方法,也许MFSideMenu会覆盖uinavigationcontroller委托?我怎样才能使这个导航控制器委托方法再次“激活”?
答案 0 :(得分: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];
通过这种方式正确分配了代表......