I use SWRevealViewController in my project. My app have TabBarController. I did that I open the menu. When I select in menu it open without TabBarController bottom. I use Storyboard. My start View is ViewController with class SWRevealViewController. I connect to my menu with identifier sw_rear and class SWRevealViewControllerSegueSetController. Before menu I have Navigation Controller. I also connect SWRevealViewController to my TabBar with identifier sw_front and class SWRevealViewControllerSegueSequeController. What am I doing wrong?
In my menu to open a View I have this code:
BookTableViewController *m = [self.storyboard instantiateViewControllerWithIdentifier:#"Book"];
[self.revealViewController pushFrontViewController:[[UINavigationController alloc] initWithRootViewController:m] animated:YES];
[self.revealViewController setFrontViewPosition:FrontViewPositionLeft animated:YES];
//Tabbar controller name on storyboard
Tabbarcontroller *tabvc=(Tabbarcontroller *)[self.storyboard instantiateViewControllerWithIdentifier:#"TabbarcontrollerVCId"];
NSLog(#"tabvc controller ===>%#",tabvc.viewControllers);
Select viewcontollers and pass index
tabvc.selectedIndex=0;
[self.revealViewController setFrontViewController:tabvc];
[self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
From what I understand, you want the front viewcontroller to be a tab bar and a menu with no tab bar?
So there are three things, front, rear and right. If you have not already look at the AppDelegate in RevealControllerExample and try do the following,
Create an instance of your tabbar
Create SWRevealViewController, init with nil as the rear and your tabbar as the front (if you can't use nil as the rear, just create a UIViewController, but you won't use it).
Create you menu viewcontroller and assign it to the rightViewController property of the SWRevealViewController
If this does not solve your problem please comment, good luck.
Related
I have used SWRevealViewController to create side bar. As in this I have used my HomeViewController as front and SidebarViewController as right.
My SidebarViewController contain a UITableView(Having different subject names). I want to open a new ViewController say QuestionsViewController on selection of any subject.
Now my problem is I want to use SWRevealViewController again to have a sidebar in QuestionViewController but in SWRevealViewController identifier for front segue sw_front is a constant string so how can I change it or having any other way to have that sidebar in QuestionViewController also.
In Short : Can we have same sidebars in different ViewControllers using SWRevelViewController
Try this one:
create NavigationViewController with HomeViewController,
segue the RevealViewController to the NavigationController as "reveal view controller set controller",
segue HomeViewController to the QuestionViewController as "show",
on both add "bar button item"(named:"OpenSideBar") on the left of the NavBar,
create an outlet to both in their swift files and add to your viewDidLoad next:
OpenSideBar.target = self.revealViewController()
OpenSideBar.action = Selector("revealToggle:")
**worked for me
Simply connect your RevealViewController to your new view controller with "reveal view controller set controller" segue
I got a solution for this, we can change front and rear ViewControllers by using following code.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]];
[self.revealViewController setRightViewController:[storyBoard instantiateViewControllerWithIdentifier:#"SideBarVC"]]; // To change rightViewController
[self.revealViewController setFrontViewController:[storyBoard instantiateViewControllerWithIdentifier:#"HomeVC"] animated:YES]; // To change frontViewController
For this we have to use SWRevealViewControllerSeguePushController as segue class for other FrontViewControllers
Thanks everyone for your help.
Currently I'm using storyboards to segue between controllers. I have a UITabBarController with a UINavigationController for each tab.
All my root UIViewControllers in their UINavigationControllers return the following when I log out the tab bar controller:
Tab Bar Controller: <UITabBarController: 0x7f7ff958d3b0>
However when I programmatically push in a new VC in the following manner:
//Show New VC
UISecondViewController *secondController = [[UISecondViewController alloc] init];
[self.navigationController pushViewController:secondController animated:YES];
and log out the tab bar controller in secondController, I see:
Tab Bar Controller: null
What's going on here?
Update:
At first I thought it could be an issue with using multiple storyboards, but when I push secondController in store.storyboard using a storyboard segue it works perfectly. The problem is this subclass controller I'm trying to push was built to only work programmatically (third party).
Main.storyboard
Store.storyboard
I'm beginner developer apps I have stroyboard with 2 UIViewController can how do a push animation without navigation bar
You don't need a navigation bar for pushing. It is just a UI component.
You can choose to remove it by
[self.navigationController setNavigationBarHidden:NO animated:YES];
UINavigationController is the stack which enables pushing.
Hold the "control" key, and drag from viewControllerA to viewControllerB in the storyboard.
you need to embed your rootViewController into a NavigationController. Could make with storyboard. Click on your Controller. Editor -> Embed In -> NavigationController.
Then you can fire push-navigation.
UIViewController *controller = ...;
[self.navigationController pushViewController:controller animated:YES];
I have a tab bar controller with a button like so:
- (void) addButtonPressed:(UIButton *) sender
{
[sender setBackgroundColor:[UIColor regularColor]];
PostViewController *post = [[PostViewController alloc] init];
[self.navigationController pushViewController:post animated:YES];
}
This code runs but the PostViewController is never shown and the tab bar controller remains.
How do I get to push to a new controller?
The NavigationController was created and StartViewController was add as rootController.
Then in StartViewController I have:
TabBarController *tab = [[TabBarController alloc] init];
// Presentation
[self presentViewController:tab animated:NO completion:nil];
in tab bar you need to create separate Navigation Controllers.
Suppose there are 3 tabs A, B and C. All the three tabs have functionality of navigation from one view to another. than you need to create three separate Navigation controllers eact pointing to Tab A, B and C. In this way you can navigate to any class within the specific Tab.
Check out this link for more details.
Hope this will help you. Happy coding :)
You may need to embed your tab bar controller within a navigation controller, In your storyboard click on your tabbarController so that it is highlighted with all the blue lines and then go to Editor in Xcode choose embed IN> UINavigationController ..If you want to do it programatically then in your AppDelegate where you setup your Window just Use This::
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:tabBarController];
navigationController.toolbarHidden=YES;
navigationController.navigationBarHidden=YES;
self.window.rootViewController =navigationController;
if you are using .xib then you have to use NSBundle to load nib
if you are using storyboard then you need to use prepareForSegue to pass on data or just display it out
In my application 2 tabs are there. I am adding tabbarController to the window with two view controllers viewcontroller1 and viewcontroller2 in didFinishLaunchingWithOptions. Now I need to add a button in the viewcontroller1 and in the button action i need to push a new viewcontroller nextViewController. To do this in the button action, i had created a navigation controller and sets its rootview controller as viewcontroller1 and then i push the nextViewController through that navigation controller. But the nextViewController is not getting loaded. Why?
(void) buttonAction {
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:self];
nextViewController *nextViewControllerObj = [[nextViewController alloc]init];
[self.navigationController pushViewController:nextViewControllerObj animated:YES];
}
Instead of adding first tab view controller into UINavigationController, please try adding main UITabBarController into UINavigationController in "didFinishLaunchingWithOptions".