I am using MVYSideMenu in my application and I can present new controller using "changeContentViewController" of MVYSideMenu but it presents new controller so from here I want to pop back to my root(HomeViewController) so I have done lot of research on this but couldn't find solution.
So if anybody knows the solution please help me.
Thanks in advance.
MVYSideMenu is making rootViewController, when you are trying to open any view from this. If you are making rootViewController, then you can not able to pop from that.
So if you want to go back, then you have to Push that view instead of making rootViewController.
I think, Right Now you are using following code for open any controller for side menu:
ChildViewController *contentVC = [[ChildViewController alloc] initWithNibName:#"ChildViewController" bundle:nil];
appDelegate.nav = [[UINavigationController alloc] initWithRootViewController:contentVC];
appDelegate.nav.navigationBarHidden=TRUE;
[[self sideMenuController] changeContentViewController:appDelegate.nav closeMenu:YES];
So Please use following code instead of above code. Here nav is object of UINavigationController in AppDelegate.
ChildViewController *contentVC = [[ChildViewController alloc] initWithNibName:#"ChildViewController" bundle:nil];
[appDelegate.nav pushViewController:contentVC animated:YES];
[[self sideMenuController] changeContentViewController:appDelegate.nav closeMenu:YES];
So You can able to push any view from side menu. And Now just try to pop this view. I am sure that you can able to pop this view after using this.
Make sure that, If you do this, then may be memory leakage is there. Because all times viewControllers are adding to the navigation controller. So My suggestion is, don't do this, if you can convince your client. :) Otherwise, you have to make your own side menu.
EDIT :-
Yes we can able to enable / disable side menu for some view controllers. Please add following methods into MVYSideMenuController.m file. And call this method from viewWillAppear of your viewControllers.
- (void)addGestures {
if (!_panGesture) {
_panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:#selector(handlePanGesture:)];
[_panGesture setDelegate:self];
// [self.view addGestureRecognizer:_panGesture];
}
if (!_tapGesture) {
_tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:#selector(toggleMenu)];
[_tapGesture setDelegate:self];
[self.view addGestureRecognizer:_tapGesture];
}
}
- (void)removeGestures{
[self.view removeGestureRecognizer:_panGesture];
_panGesture = nil;
}
You can easily call this methods LocalNotifications. May be addGestures already there. You can remove gestures by calling removeGestures method when you needed in your controller. But do not forgot to addGestures when you needed side menu after removing gestures.
Hope, this is what you're looking for. Any concern get back to me. :)
Related
I have a very simple design with 3 views (.xib):
MeuPrimeiroViewController
MeuSegundoViewController
MeuTerceiroViewController
I am using the SplitViewController class to divide the screen into two parts, by default is configured on only appdelegate.m class to split views 'MeuPrimeiroViewController' along with 'MeuSegundoViewController'.
All Im trying to do is, when the user tap the button inside my 'MeuPrimeiroViewController', he start a method existing inside my 'MeuSegundoViewController' and he push the 'MeuTerceiroViewController', for this I'm doing:
MeuPrimeiroViewController.m
-(IBAction)mudar:(id)sender{
MeuSegundoViewController *VC2 = [[MeuSegundoViewController alloc] init];
[VC2 mudar];
}
MeuSegundoViewController.m
-(void)mudar{
NSLog(#"Change Screen");
MeuTerceiroViewController *VC3 = [[MeuTerceiroViewController alloc] init];
[self.navigationController pushViewController:VC3 animated:YES];
}
The method 'mudar' is calling but the screen don't change, how to solve this problem?
If you want to change the detail view you should make in MeuPrimeiroViewController:
[self.splitViewController showDetailViewController:VC3 animated:YES];
If you want to change the the "list" view you should make in the MeuPrimeiroViewController:
[self showViewController:VC2 animated:YES];
I'm not sure if it's VC2 or VC3 you want to show, but I hope this helps!
I'm trying use Kal calendar in my project. Here is what I understand to be the case so far:
Whichever view controller that calls Kal must implement the UITableViewDelegate method "didSelectRowAtPath"
Issue:
My view controller that calls Kal already has an existing tableview (one of the cells would call Kal)
To solve this, I've attempted to push an intermediary view controller from a cell in my main tableview as follows:
ScheduleViewController *svc = [[ScheduleViewController alloc] init];
[svc setTitle:#"Schedule"];
[self.navigationController pushViewController:svc animated:YES];
From ScheduleViewController's viewDidLoad, I'm pushing the actual Kal calendar:
KalViewController *kal = [[KalViewController alloc] init];
[kal setDelegate:self];
[kal setTitle:#"Schedule"];
[self.navigationController pushViewController:kal animated:NO];
So once I do this, I can get the calendar to show up. However, I can't seem to cleanly get back to my main menu using the back button. I created a back button in ScheduleViewController:
[kal.navigationItem
setBackBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:#"Back"
style:UIBarButtonItemStyleBordered
target:self
action:#selector(test)]];
I've put this in a few different places (viewDidLoad, viewWillAppear) and can't get it to work. When I click "Back" it still goes to ScheduleViewController instead of all the way back. "test" never gets called. I've tried popToRootViewController, [[self.presentingViewController presentingViewController] dismissViewController], and a few others. Just doesn't want to work.
Is this the best way to go about using Kal?
How can I popToRootViewController (skipping ScheduleViewController) using this method?
Thanks! This is my first post so please let me know if there's anything I can do to make the question less confusing.
Well, finally got it I think. I ended up removing the intermediary view controller. I think I just didn't understand what was going on earlier...I've now done the following:
instead of my main view controller (w/the existing tableview) being the delegate, I made the KalDataSource also be the UITableViewDelegate. So my DataSource handles both populating the calendar and selection of an event.
added id datasource as in ivar in main view controller
changed the "didSelectRowAtPath" method to:
dataSource = [[EventsDataSource alloc] init];
KalViewController *kal = [[KalViewController alloc] init];
[kal setDelegate:dataSource];
[kal setDataSource:dataSource];
[kal setTitle:#"Schedule"];
[self.navigationController pushViewController:kal animated:YES];
Everything now appears to be okay.
There's too much black space between the Kalendar and the navigation bar. Here's a picture of what I'm talking about:
I'm calling the code from ViewDidLoad of a ViewController that I have in my storyboard:
- (void) viewDidLoad {
KalViewController *calendar = [[KalViewController alloc] init];
[self.view addSubview:calendar.view];
}
I'm just learning to use Kal. Maybe I'm going about incorporating it in the wrong way. I sure do like using the storyboard to link up my views so my viewcontroller includes "Kal.h" and I instantiate as shown in the code above. I tried to make the viewcontroller a subclass of KalViewController but that didn't work.
Maybe there's a more elegant way of incorporating Kal into a hierarchy of storyboarded view controllers?
Just add the following:
[[self navigationController] initWithRootViewController:calendar];
[[calendar navigationItem] setHidesBackButton:YES];
and it should do the trick. The second line is being used to hide the "Back" button that otherwise becomes visible, but for me it's a single screen app, you may or may not want to use it.
I used the exact same code as you initially did ACB, had the exact same problem but I also had included [self addChildViewController:calendar]; after the creation of the calendar view.
What does this code do? [self addChildViewController:calendar];
I understand it "adds a child view controller" but what is REALLY going on.... and should I need this? Apparently not because you didn't, and I just compiled my code without it and there was no difference.
Overall code:
KalViewController *calendar = [[KalViewController alloc] init];
[self.view addSubview:calendar.view];
//[self addChildViewController:calendar];
I am inside a root view controller. and then allocate the secondviewcontroller
SecondViewControl *second=[[SecondViewControl alloc] init];
[self presentModalViewController:second animated:NO];
The second viewcontroller 's view not showing up
AddSubView method works though.
[self.view addSubView:second.view];
why presetModalViewController is not working?
Usually you'll allocate the SecondViewControl with a .xib file that actually defines the user interface. Consider using a line like this (broken for readability):
SecondViewControl *second = [[SecondViewControl alloc]
initWithNibName:#"SecondView"
bundle:nil];
Without the accompanying .xib to define the view, you may be left with a view controller that doesn't have the necessary properties set to actually support user interaction, and so presentModalViewController: may have trouble there.
Preface: I am not using *.xib files.
I instantiate a UINavigationController in a class that effectively serves as my 'rootViewController'. This 'rootViewController' also has two UITableViewController members that are drawn on different sections of the iPad screen. One of which is set as the root view for the navigation controller. Let's call it tableViewControllerA.
The problem is, when I invoke pushViewController on a valid UINavigationController, I see no effect:
[tableViewControllerA.navigationController pushViewController:tableViewControllerX animated:YES];
I've gathered from the posts I've searched today, that this push method should in turn cause the screen to redraw the top of stack controller.view. This is not what I'm seeing.
It seemed there was a disconnect in my implementation, and it was time to reference a working example in my environment (xcode 4.0). Assuming the canned templates would provide a working basis, I created a new navigation-based applications. I simply modified didFinishLaunchingWithOptions: as follows.
UIViewController *view1 = [[UIViewController alloc] init];
UIViewController *view2 = [[UIViewController alloc] init];
view1.title = #"view1";
view2.title = #"view2";
[self.navigationController pushViewController:view1 animated:YES];
[self.navigationController pushViewController:view2 animated:YES];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:view1];
[view1 release];
[view2 release];
I found similar results. When I launch the simulator the screen title reads the title of whatever the self.window.rootViewController is pointing at. With the code as is, the title of the resulting top screen reads "view1". When I initWithRootViewController:view2, the resulting top screen reads "view2".
So please tell me I'm stupid cuz xyz...
Thanks.
Here are some references and suggestions:
Simple tutorial for navigation based application:
http://humblecoder.blogspot.com/2009/04/iphone-tutorial-navigation-controller.html
Here is another one to create the step by step navigation controller and adding the views:
http://www.icodeblog.com/2008/08/03/iphone-programming-tutorial-transitioning-between-views/
and here a bit advance with navigation + tab bar controller:
http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/CombiningToolbarandNavigationControllers/CombiningToolbarandNavigationControllers.html
Without seeing your code, I have 2 theories:
Your syntax and calls are wrong when you do the push. Use this as a model:
-(void)Examplemethod {
AnotherClassViewController *viewController = [[[AnotherClassViewController alloc] initWithNibName:#"AnotherClassView" bundle:nil] autorelease];
[self.navigationController pushViewController:viewController animated:YES];
}
You are never adding the navigation controller to the view hierarchy which never adds the view either. Take a look at this.