mikefrederick / MFSideMenu

Facebook-like side menu for iOS
Other
1.17k stars 291 forks source link

How to pop a view controller which I pushed from the side menu? #122

Closed iDev21 closed 11 years ago

iDev21 commented 11 years ago

Hi

I have a center view controller & have added a right side menu. After pressing a button in the menu, I am pushing a view. How do I pop back to the center view controller from this view?

mikefrederick commented 11 years ago

What do you mean you're "pushing a view"? Your centerViewController is a navigation controller and you're pushing a new view controller onto it? If so, then all you have to do is [centerViewController popViewControllerAnimated:YES];. If that's not what you meant then you'll have to explain the situation more clearly.

iDev21 commented 11 years ago

Thanks for reply. But How to get centerViewController object in pushed view controller??

mikefrederick commented 11 years ago

You would just do:

[self.navigationController popViewControllerAnimated:YES];
iDev21 commented 11 years ago

I had tried this before I raised the issue. It's not working for me. I have Dashboard View in that a right side bar as MFMenu and after click the button from side bar i pushed a view controller. Now i want go back to Dashboard .

How do i do that?

xeravim commented 11 years ago

in the didSelectRowAtIndexPath I simply put this code:

HomeController *Home = [sb instantiateViewControllerWithIdentifier:@"HomeController"]; 
NSArray *controllers = [NSArray arrayWithObject:Home];
navigationController.viewControllers = controllers;

and voilla it will make you back to the centerViewController.

iDev21 commented 11 years ago

@xeravim But i dont have UITableView in side menu. I have UIButton and i write below code in it's IBAction method.

SampleViewController VC = [[SampleViewController alloc]initWithNibName:@"SampleViewController" bundle:nil]; UINavigationController navigationController = self.menuContainerViewController.centerViewController; NSArray *controllers = [NSArray arrayWithObject:VC]; navigationController.viewControllers = controllers; [self.menuContainerViewController setMenuState:MFSideMenuStateClosed];

xeravim commented 11 years ago

here I did some testing. It seems that your codes are right, so I change the sidemenu to an UIViewController. there are two buttons in my sidemenu. But I am using storyboard here.

- (IBAction)BackToHome:(id)sender {
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                             bundle:nil];
UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
DemoViewController *loginVC = [sb instantiateViewControllerWithIdentifier:@"DemoViewController"];
NSArray *controllers = [NSArray arrayWithObject:loginVC];
navigationController.viewControllers = controllers;
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
}

- (IBAction)toDifferentView:(id)sender {
UIStoryboard* sb = [UIStoryboard storyboardWithName:@"MainStoryboard"
                                             bundle:nil];
UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
UIViewController *loginVC = [sb instantiateViewControllerWithIdentifier:@"ViewController"];
NSArray *controllers = [NSArray arrayWithObject:loginVC];
navigationController.viewControllers = controllers;
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed];
}

Maybe you set a wrong nibName, check it again.

xeravim commented 11 years ago

Or maybe your SampleViewController not a child from UINavigationController.

iDev21 commented 11 years ago

Sidebar is one view controller and it's open on PanGesture from Dashboard . in Sidebar view controller i wrote

and calling UIButton IBAction as previous comment and open SampleViewController . Now I want to open Dashboard from sampleviewcontroller's back button.

I checkd XIB name , it's correct .

mikefrederick commented 11 years ago

I can't tell what is going on here. @iDev21 if you want to fork the project and modify one of the demos to replicate this issue I can take a look.

iDev21 commented 11 years ago

Hello mike , I had solved that issue . If user have multiple UIButton in MFSidemenu which use for navigate to new viewcontroller and if user want navigate to previous view which have have sidemenu than use below code for UIButton IBAction .

NewViewController *newVC = [[NewViewController alloc]initWithNibName:@"NewView" bundle:nil];
UINavigationController *navigationController = self.menuContainerViewController.centerViewController;
[navigationController pushViewController:newVC animated:NO];
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed]; 

Thanks a lot guys for participating and help . Issue Closed

erhandemirci commented 10 years ago

thank you iDev21 :+1: