MMDrawerController with Storyboard - objective-c

in my project i would like to use the MMDrawerController plugin ( https://github.com/mutualmobile/MMDrawerController ) but i have a problem. In the project i'm using the storyboard so i have read this post http://pulkitgoyal.in/side-drawer-navigation-for-ios/ but the plugin doesn't works.
I have the root view controller that calls another view (the drawer) with a segue and so it use this method (as written in the guide)
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"DRAWER_SEGUE"]) {
MMDrawerController *destinationViewController = (MMDrawerController *)segue.destinationViewController;
// Instantitate and set the center view controller.
UIViewController *centerViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"FIRST_TOP_VIEW_CONTROLLER"];
[destinationViewController setCenterViewController: centerViewController];
// Instantiate and set the left drawer controller.
UIViewController *leftDrawerViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"SIDE_DRAWER_CONTROLLER"];
[destinationViewController setLeftDrawerViewController: leftDrawerViewController];
}
}
When the destionation view is loaded i see only the centerView without the Side drawer controller. Why?
Thanks in advance.

Did you tried opening the side view controller on some action on center view controller?
e.g.,
- (IBAction)menuTapped:(id)sender {
[self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
}
this will open up the side drawer for you.
EDIT:
Else simply write the following code in your Center view controller's viewDidLoad,
self.mm_drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModePanningCenterView;
self.mm_drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureModePanningCenterView;
You can change the gesture mode as per your requirement.

Related

How to hide masterView for UISplitViewcontroller in IOS8

All,
I have met a problem with new UISplitViewcontroller in IOS8 for iPad. I have a UITableView in the storyboard in the detailViewcontroller and on clicking the cell, I should go to the another view called "detailinfo". I am current using a "show" segue.
However, the current segue just push on the right part. I wanna it show fullscreen , but I dont know how to make it, I tried using preferredDisplayMode property of the splitViewController , the result is it just hide the master view but didnt resize the detailView. I dont wanna using present as modal.
current way I am doing is
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier]isEqualToString:#"showStudentDetail"]){
if(self.traitCollection.horizontalSizeClass != UIUserInterfaceSizeClassCompact){
UISplitViewController *splitViewController = (UISplitViewController *)self.navigationController.parentViewController;
splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
}
}
}
and in viewDidAppear, using
- (void)viewDidAppear:(BOOL)animated {
if(self.traitCollection.horizontalSizeClass != UIUserInterfaceSizeClassCompact){
UISplitViewController *splitViewController = (UISplitViewController *)self.navigationController.parentViewController;
splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAutomatic;
}
}
This will work , but the masterViewController will "Jump out" which has a very bad visual effect.
Hope can get any help , thank you
UISplitViewController is a complex view controller which consists of two child view controllers. So when you use some segue which is added to any of the child view controller you ask child view controller to perform the segue. And this child view controller has partial control of active window.
In your case you need to ask the split view controller to perform the segue. So you should add the segue to your split view controller which handles active window. This way you will have the fullscreen option.
UPDATE
If you dont wanna using present as modal and want to avoid "Jump out" effect you can hide master using animation
UISplitViewController *splitViewController = [self splitViewController];
[UIView animateWithDuration:0.25 animations:^{
splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModePrimaryHidden;
} completion:^(BOOL finished) {
[splitViewController showDetailViewController:vc sender:nil];
}];

Switch from view controller to custom tab bar controller

I have an application that has an initial view controller that allows the user to log in. After the users logs in I'm trying to change the view to a custom tab bar controller that is of class type TabViewController. The problem is that when I switch to the tab bar controller, the screen is black and the bottom tab bar is gray and empty.
Here is some relevant code:
in ViewController.m (initial log in view)
- (IBAction)logInButtonClicked:(UIButton *)sender
{
TabViewController *tabView = [[TabViewController alloc] initWithSession:session];
[self presentViewController:tabView animated:YES completion:nil];
}
in TabViewController.m (class assigned to the tab bar controller)
-(id) initWithSession: (Session*) s
{
self = [super init];
if (self)
{
session = s;
}
return self;
}
Note that when I do the default initialization like so:
TabViewController *tabView = [[TabViewController alloc] init];
I get the same result.
How can I make my tab view controller look like it does in my storyboard on initialization?
Storyboard:
What the tab view controller looks like in the simulator:
I'm not sure this is the best way but it's exact what I did in my last app and it works fine.
Try making the tab bar view controller the root/initial view controller of your app.
According to Apple's developer class reference:
When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.
After doing this, set up a modal segue in the storyboard from the tab bar view controller to the login view controller, name it "segueLogin" and call it manually in viewDidAppear method of your tab bar view controller class.
if(!userHasLogin){
[self performSegueWithIdentifier:#"segueLogin" sender:self];
}
its really easy,
i will try to solve your problem in two step.
step 1-- select your TabViewController in storyboard and give it a identifier(below the custome class of TabViewController)
step 2--
- (IBAction)logInButtonClicked:(UIButton *)sender
{
UIStoryboard *storyBoard=[UIStoryboard storyboardWithName:#"Your_Story_Board_Name" bundle:nil];
TabViewController *tabView = [storyBoard instantiateViewControllerWithIdentifier:#"TabViewController_Identifier_From_Storyboard"];
[self presentViewController:tabView animated:YES completion:nil];
}
You should create your's TabViewController with UIStoryboard's - (id)instantiateViewControllerWithIdentifier:(NSString *)identifier
In yours case creating with [[TabViewController alloc] init] is wrong, you doesn't create all tabs programmatically.

prepareForSegue not being called from UITableView in a UIViewController

I have a UIViewController that contains a UITableView. The table view contains a custom UITableViewCell. The custom cell was built in interface builder and has a nib. In my main storyboard, I dragged a segue from the custom table view cell to the destination view controller. I set up the bare bones essentials in prepareForSegue, set a break point, but it never gets called.
I'm not that accustomed to using a UITableView in a view controller. I usually use a UITableViewController, but requirements dictate using the table view in a view controller. My initial assumptions is that most methods of doing things would be nearly identical, but I'm finding that not to be the case.
I tried setting the segue from the view controller itself and using didSelectRowAtIndexPath, and though it worked, the transition to the destination view controller was jerky.
Can anyone suggest what I might be missing in order to cause the prepareForSegue method to fire?
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
GaugeViewController *destination = [segue destinationViewController];
[destination setGaugeID:#"1"];
}
Thanks!
You need to refer to the identity of the segue in the Storyboard, something like this:
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
GaugeViewController *destination = segue.destinationViewController;
if([segue.identifier isEqualToString:#"yourSegue"]) {
NSLog(#"prepareForSegue called");
[destination setGaugeID:#"1"];
}else {
// do something else
}
}
Also don't forget to set the Identifier in the Storyboard.
Remember that push segues are used with Navigation Controllers and a modal segue can be dragged from view controller to view controller.

How to presentModalViewController without dismiss the TabBarController

Hey guys i`m trying to present a modal view controller inside an application with a tab bar controller. The problem is, every time the new view is presented, it on top of my tab bar.
I need to keep my tab bar even when the view is presented. Like google maps application does with his toolbar at the bottom of the screen.
How can i do that?
Thank you
By default, a modal view controller is meant to take up the entire screen (on an iPhone/iPod, at least). Because of this, it covers whatever you have on screen at the time.
A view controller presented via modal segue is meant to live on its own. If you want to keep your Navigation and TabBar, then just use a push segue to present the new ViewController. Remember to use this kind of segue, your presenting controller needs to be part of a UINavigationController already.
Use this to push a ViewController. If it is a UINavigationController it will push its linked RootViewController by itsself.
Create a viewController to push: (Using Storyboard)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"LoginViewController"];
or (Using Code/Nibs)
LoginViewController *viewController = [[LoginViewController alloc] init]; //initWithNibNamed in case you are using nibs.
//in case you want to start a new Navigation: UINavigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
and push with:
[self.navigationController pushViewController:vc animated:true];
Also, if you are using Storyboards for the segues you can use this to do all the stuff. Remember to set the segue identifier.
[self performSegueWithIdentifier:#"pushLoginViewController" sender:self]; //Segue needs to exist and to be linked with the performing controller. Only use this if you need to trigger the segue with coder rather than an interface object.
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:#"pushLiftDetail"]) {
[[segue.destinationViewController someMethod:]];
segue.destinationViewController.someProperty = x;
}
}
I think you'll need to add a UITabBar to the modal view and implement/duplicate the buttons and functionality that your main bar has. The essence of a modal window is it has total control until it is dismissed.
You might try putting your UITabBarController into a NavBarController, but I'm not certain that this will work.
UITabBarController -> NavBarController -> Modal View

navigation controller is null when pushing new view

I have a tab bar application and in one of those tabs I have a map view. I am trying to push a new view from clicking a disclosure button on an annotation on the map view using this code...
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
childController = [[AnnotationDetailView alloc] initWithNibName:#"AnnotationDetailView" bundle:nil];
[self.navigationController pushViewController:childController animated:YES];
}
however if I nslog the navigationController it is null.
What is confusing is that in another tab I have a table view which will push a view using the above code. Why does that work but an map annotation doesn't.
The simple answer is that your table view is inside a navigation controller and your map view isn't. A tab view controller isn't actually a navigation controller itself.
Depending on your project, the fix may be as simple as editing your XIB so that a navigation controller is the immediate child of the tab controller for the map's tab, and the map view controller is the child of that navigation controller. Look at how your table view is defined, and you should be able to see what's different.
Have you defined childController as AnnotationDetailView * childController; in your header?
or you can simply use:
AnnotationDetailView * childController = [[AnnotationDetailView alloc] initWithNibName:#"AnnotationDetailView" bundle:nil];