我在TabBarController中使用MFSideMenu在SideMenu中我添加了UITableview所以当我点击单元格然后它导航到另一个视图控制器但它没有导航到该视图控制器
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
centerViewController = [storyboard instantiateViewControllerWithIdentifier:@"Tabbarcontroller"];
TabViewController1 *tableView = [storyboard instantiateViewControllerWithIdentifier:@"TabViewController1"];
UINavigationController *nav1 = [[UINavigationController alloc] initWithRootViewController:tableView];
TabViewController2 *tableView2 = [storyboard instantiateViewControllerWithIdentifier:@"TabViewController2"];
UINavigationController *nav2 = [[UINavigationController alloc] initWithRootViewController:tableView2];
centerViewController.viewControllers = @[nav1,nav2];
UIViewController *leftSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:@"SideViewController"];
container = [MFSideMenuContainerViewController
containerWithCenterViewController:centerViewController
leftMenuViewController:leftSideMenuViewController
rightMenuViewController:nil];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
return YES;
}
SideMenu.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
ViewController3 *objEdit =[self.storyboard instantiateViewControllerWithIdentifier:@"ViewController3"];
AppDelegate *objApp = (AppDelegate *)[[UIApplication sharedApplication]delegate];
UINavigationController *navigationController = (UINavigationController *) objApp.centerViewController.navigationController;
NSLog(@"navigationcontroller :%@",objApp.centerViewController.navigationController);
[navigationController pushViewController:objEdit animated:YES];
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
}
答案 0 :(得分:1)
objApp.centerViewController是tabbarcontroller,所以你需要先从tabor控制器中找出所选的视图控制器。如果你想在选定的选项卡中推送控制器,你应该从tabbarcontroller的SelectedViewCOntroller获取Navigationcontroller。
UINavigationController *navigationController = (UINavigationController *) objApp.centerViewController.selectedViewController;
[navigationController pushViewController:objEdit animated:YES];