Rushabh Rushabh - 1 month ago 13
Objective-C Question

MFSideMenu side Viewcontroller not navigate to Specific view controller in Tabbarcontroller

I am using MFSideMenu in TabBarController In SideMenu i have added UITableview so when i click on cell then it navigate to another view controller but its not navigate to that view controller

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];

}

Answer

objApp.centerViewController is tabbarcontroller, So you need to find out selected view controller from tabor controller first. If you want to push controller in selected tab, You should get Navigationcontroller from SelectedViewCOntroller of tabbarcontroller.

UINavigationController *navigationController = (UINavigationController *)   objApp.centerViewController.selectedViewController;

  [navigationController pushViewController:objEdit animated:YES];
Comments