Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SWRevealViewController project in iOS

Note: Problem solved.

Here comes the story. I am using RevealViewController in my project. I am also hiding the navigationBars:

[self.navigationController setNavigationBarHidden];

My project can be seen in the picture below and the "menuButton" is implemented in the tabBarViewController.

enter image description here

Since the navigationBar is hidden due to my interface looks, all tabViews (HomeViewController) will not show the menuButton and the navigationBar as supposed to. I am not using panGestureRecognizer to trigger the menu aswell.

This means I have a problem to trigger the menu via a normal button in HomeViewController. The menuButton-event is placed in tabBarViewController.m:

_menuButton.target = self.revealViewController;
_menuButton.action = @selector(revealToggle:);

So I tried to call a method from HomeViewController to fire the button in tabBarViewController like this:

HomeViewController.m

- (IBAction) onMenuClicked: (id)sender{

tabBar = [[tabBarViewController alloc] init];
[tabBar setupMenu]:
}

tabBarViewController.m

-(void) setupMenu{

[_realMenuButton sendActionForControlEvents:UIControlEventTouchUpInside];
[_realMenuButton addTarget:self.revealViewController action:@selector(revealToggle:) UIControlEventTouchUpInside];
}

In this example I tried to make the realMenuButton and normal UIButton. Ive also tried as a UIBarButtonItem just to trigger the @selector(revealToggle:) But nothing happens in the app when I try to trigger the button from HomeViewController.

Not sure how I shall make this work. Any other Ideas or tricks? Please be specific if so! Regards

like image 538
Jesper Martensson Avatar asked Aug 10 '15 21:08

Jesper Martensson


3 Answers

Yes, it will still work. SWRevealViewController is just a subclass of a UIViewController, so you can use it at any point in the app:

  1. By calling presentViewController:animated at some point.
  2. By using it in a navigation stack etc.

Note that you can add gestures from SWRevealViewController to its content view controllers, which will alter the behaviour of used in a navigation view controller, but that's to be expected, and you still have full control over its behaviour.

Edit

The UI structure of your app is still not clear to me - it looks like you're trying to call revealToggle on an instance of SWRevealViewController when the VC in view is infact HomeViewController? How would this work, when SWVC is not even in view?

My best guess is that your UI structure should be as follows:

TabBarController --->(root)UINavigationController --->(root)SWRevealViewController.

Then, on your SWRevealViewController, set HomeViewController as the front view controller, and the TableViewController as the right or left view controller.

like image 115
Vinod Vishwanath Avatar answered Nov 17 '22 12:11

Vinod Vishwanath


Do you mean like this?

tabbar controller with menu button?

it is possible. you can set the menu button in your tabBarController.m, like this :

UIBarButtonItem *menu = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"menu.png"] style:UIBarButtonItemStylePlain target:revealController action:@selector(revealToggle:)];

self.navigationItem.leftBarButtonItem = menu;
self.delegate = self;

For me, my initial view controller is the login screen (obviously I don't need reveal any VC here...). then when user tap the login button,

UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:yourRootVC];
LeftMenuViewController *leftMenuVC = [[LeftMenuViewController alloc]init];
SWRevealViewController *revealController = [[SWRevealViewController alloc]initWithRearViewController:leftMenuVC frontViewController:nav];
revealController.delegate = self;
[self presentViewController:revealController animated:YES completion:nil];
like image 36
One Eyed Raven Avatar answered Nov 17 '22 12:11

One Eyed Raven


I've tried it and it should work as normal. Even it isn't initial view controller

like image 4
Vitalii Gozhenko Avatar answered Nov 17 '22 11:11

Vitalii Gozhenko