How to implement both tab bar and side menu in ios? - ios

For sidemenu I am using the SWRevealViewController framework and For tab-bar I am taking 3 Viewcontrollers example A, B and C. I want to display tab bar in initial Viewcontroller for that purpose in didfinishlaunch
method in app delegate. I have mentioned front viewcontroller as tab-bar and rear Viewcontroller as side menu and I am also successful in moving to side menu. But from that side menu I am unable to navigate the view controller. Please suggest me
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
SideMenuViewController *sidemenuVc = [storyboard instantiateViewControllerWithIdentifier:#"SideMenuViewController"];
HomeViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"HomeViewController"];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:sidemenuVc frontViewController:vc];
//[self .navigationController.pushViewController:vc animcated:YES];
[self.navigationController pushViewController:revealController animated:YES];

You should create storyboard like this
or try below one

Related

IOS/Objective-C/Storyboard: Prevent ViewController From Launching Modally

I want a viewcontroller to launch using a show transition, not modally from the bottom. Normally when I use the following code that's what happens. However, in this case, it is launching as a modal controller from the bottom up. Is there a switch I don't know about or could something be set in Storyboard that is causing this VC to launch modally from the bottom instead of showing?
UIStoryboard *storyBoard = self.storyboard;
IDImportEventsOnboard *importEvents =
[storyBoard instantiateViewControllerWithIdentifier:#"importEventsOnboard"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: importEvents];
[self presentViewController:nav animated:YES completion: nil];
The VC is embedded in a navigation controller.
Should I be using showViewController directly to the targetVC without going through the Nav? Or a pushViewController What is a proper, robust way to show a VC with a show transition?
Thanks in advance for any suggestions.
In the above code you are 'presenting' a new NavigationController from a ViewController. In order to do a push/show transition, that needs to be done on an instance of a NavigationController. If your current ViewController is already in a NavigationController, you can push the new ViewController onto the current NavigationController stack. For Example:
UIStoryboard *storyBoard = self.storyboard;
IDImportEventsOnboard *importEventsVC =
[storyBoard instantiateViewControllerWithIdentifier:#"importEventsOnboard"];
[self.navigationController pushViewController:importEventsVC animated:YES];

intially select sw_front view controller swrevealviewcontroller

I have two profile in my app. So after some initial profile setup, my app will start with different screens (firstVC or SecondVC).
So based on the initial (Consider Appdelegate :didfinish Method) setup, i wish to select "sw_front" to be firstVC or secondVC.
Every time firstVC is loaded first. If i wish to open SecondVC first, i tried is very simlpe code in viewWillAppear Method, may be incorrect:
UIViewController * sec = [self.storyboard instantiateViewControllerWithIdentifier:#"SecondID"];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:sec];
[self.revealViewController pushFrontViewController:nav animated:YES];
The issue is app directly enters firstVC, but I want it to enter directly in FirstVC or SecondVC, when needed.
Thanks, any help appreciated :)
May be you are coding wrong.Try below code when you are pushing.
UIStoryboard *storyboard = nil;
storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
SWRevealViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"SecondID"];
[self.navigationController pushViewController:vc animated:YES];

Replace Menu View Programmatically in objective c

I am using the example from AppCoda to create a slide-out sidebar menu. Here is the link.
https://www.appcoda.com/ios-programming-sidebar-navigation-menu/
What I am trying to do is replace the menu with a different menu on the mainViewController. And I want to do this programmatically. I already know how to do this directly from the storyboard.
Whenever I try this method, it replaces the entire view with the menu controller. I just want it to change the menu on the left sidebar.
NSString * storyboardName = #"Main";
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
UIViewController * vc = [storyboard instantiateViewControllerWithIdentifier:#"menu_logged_in"];
UIViewController * vcl = [storyboard instantiateViewControllerWithIdentifier:#"menu_register"];
[self presentViewController:vc animated:YES completion:nil];
Is there anyway to call the sidebar on the left menu and replace it with another menu. My knowledge in the iOS environment is very limited and I'm super confused on how to change this menu with a different menu.
So what I did was instantiated the viewController from the storyboard and then called it using the setRearViewController function and then set the new menu to that.
UIViewController *rootViewController = [storyboard instantiateViewControllerWithIdentifier:#"menu_subscriber"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
navController.navigationBar.hidden = YES;
[navController setViewControllers: #[rootViewController] animated: YES];
[self.revealViewController setRearViewController:navController];

Add semi-transparant background viewcontroller with search bar throughout app

need help in adding search bar ViewController which whose SearchBar will be in NaviagationBar with Back button (navigation search i achieved - self.navigationItem.titleView = searchBarView) throughout app, but until it has search i want to show previous ViewController in background with semi-transparent black color just like i achieved in Android :
i can add semi-transparent ViewController to current ViewController :
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
vc.view.backgroundColor = [UIColor clearColor];
[vc setTransitioningDelegate:transitionController];
vc.modalPresentationStyle= UIModalPresentationCurrentContext;
[self presentViewController:vc animated:YES completion:nil];
but what it is doing that it opens SecondViewController in transparent without NavigationBar, the FirstViewController has NavigationBar
And when the SecondViewController is opened it should have SearchBar in NavigationBar and it shouldn't be Transparent as i achieved in Android.
There will be n number of ViewController which will add this same controller as Overlay Controller with NavigationBar and back button.
Please Help.
I found some solutions which involve taking a snapshot of the view and adding them to your navBar controller.
From Apple:
https://developer.apple.com/library/ios/qa/qa1817/_index.html
Other interesting option:
iOS iPhone is it possible to clone UIView and have it draw itself to two UIViews?
In you code snippet you just create new SecondViewController and present it like modal. It appears without navigation bar because you create it without Navigation Controller.
If you want to keep SecondViewController in the same navigation stack as previous ViewController with navigation bar and default Back button you should call:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"SecondViewController"];
[self presentViewController:vc animated:YES completion:nil];
[self.navigationController pushViewController:vc animated:YES];
To make SecondViewController like semitransparent, take screenshot of previous view controller, pass this image to SecondViewController and use it like background. You can apply this image to additional ImageView on your SecondViewController view or just call:
self.view.backgroundColor = [UIColor colorWithPatternImage:self.backgroundImage];

Confused about storyboards and pushing programmatically ios Objective C

I am really confused about the relationship between storyboards and pushing to views programmatically.
I am using SWRevealViewController to display a menu of items.
If I push to the storyboard using
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
PhotosViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"PhotosViewController"];
[self presentModalViewController:controller animated:YES];
[self.navigationController pushViewController:controller animated:YES];
All of the information in my storyboard is displayed but there is no "back" button to the SWRevealViewController.
If I push to the view controller using
PhotosViewController *frontViewController = [[StreamScreen alloc] init];
newFrontController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
Then I can view everything that I have added programmatically but nothing from the storyboard.
My question is how can I access things from both storyboard and things Ive added programmatically.
if you present the view controller then it will not give you default back button because when you present a controller it will not added in navigation stack of NavigationController so it won't give you that option.
If you want push controller do not use presentModalViewController.
Try like below
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
PhotosViewController *controller = [storyboard instantiateViewControllerWithIdentifier:#"PhotosViewController"];
[self.navigationController pushViewController:controller animated:YES];
and if you want to present controller then create manually add a back button like we have default in navigation back button and on it's click write below code to dismiss the controller.
[self dismissViewControllerAnimated:YES];
Hope this helps you.

Resources