I have one tabviewcontroller and associated tab bars and view controllers as shown in the image.
My problem is, when i am trying to navigate to some inner view controllers using below code it is not even working, i have tried some other code also, some codes are navigating properly but Tabbar is missing.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UITabBarController *tabbar = (UITabBarController *)[storyBoard instantiateViewControllerWithIdentifier:#"eventList"];
self.window.rootViewController = tabbar;
[self.window.rootViewController.navigationController pushViewController:tabbar animated:YES];
i am not that much familiar with tabviewcontroller.
Change,
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UITabBarController *tabbar = (UITabBarController *)[storyBoard instantiateViewControllerWithIdentifier:#"eventList"];
self.window.rootViewController = tabbar;
[self.window.rootViewController.navigationController pushViewController:tabbar animated:YES];
With,
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
NavigationControllerOfTabbar *navVC = (NavigationControllerOfTabbar *)[storyBoard instantiateViewControllerWithIdentifier:#"navVCStoryboardID"];
self.window.rootViewController = navVC;
Problem,
You need to learn know how UITabBarController works: Read this.
You need to learn how iOS app flow/stack works, specifically for UINavigationController, UITabBarController.
In your code, this line would be nil: self.window.rootViewController.navigationController
Solution,
Create new class subclassing UINavigationController, and give first view controller's name in your storyboard.
Now initialize this with given code, and it will work.
Tab bar didn't require navigation controller to operate.
My suggestion is to remove all code give as above, and make sure that your storyboard is main interface in your target. Tabs bar should work automatically.
I've noticed that you have other tab bar controllers as children of main tab bar controller. Perhaps they are rudiments of your learning process and had to be removed.
Please make sure that you are setting up proper segues
https://imgur.com/a/WvIrh
Related
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.
I'm developing push notification on my app. I want that when people tap on push message, app open a specific controller;
If I do that with:
storyBoardName = #"MyStoryboardName";
UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];
MainWebController* MainWeb = [storyBoard instantiateViewControllerWithIdentifier:#"MainWeb"];
MainWeb.urlToLoad = URL_TO_LOAD;
self.window.rootViewController = MainWeb;
[self.window makeKeyAndVisible];
works, I can see MainWeb when i tap on push massage but the controller view cover all the screen: tab bar and navigation bar are hided!
I know that rootviewcontroller is a uitabbar:
NSLog(#"Controller: %#",self.window.rootViewController.debugDescription);
Solved with:
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
tabController.selectedIndex = 0;
UINavigationController *navigationController = (UINavigationController *)tabController.selectedViewController;
[navigationController pushViewController:MainWeb animated:YES];
You are replacing the rootViewController by setting it to be a MainWebController. Is this the initial UIViewController in your Storyboard?
From your issue it would seem that the initial UIViewConroller is a TabViewController and what you actually want is to setup a UIViewController inside this.
I've successfully implemented MFSideMenu so that all the navigation works properly except scrollsToTop in the scroll views (Specifically in my TableViewControllers and one ViewController where the UIscrollview takes up the whole frame). scrollsToTop is not working, even though it is enabled in each TableView.
I know that it's the MFSideMenu causing the issue because I removed it from the project and the scrollsToTop is working fine then.
So here's how I call the MFSideMenu from the AppDelegate on launch:
//Instantiate the Side Menu and the center view
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
UITabBarController *tabBarController = [storyboard instantiateViewControllerWithIdentifier:#"MainTabBar"];
SideMenuViewController *leftSideMenuController = [[SideMenuViewController alloc] init];
UINavigationController *leftViewNavigationController = [[UINavigationController alloc] initWithRootViewController:leftSideMenuController];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:tabBarController
leftMenuViewController:leftViewNavigationController
rightMenuViewController:nil];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
The TableViews I'm concerned with are embedded in NavigationControllers, which are embedded in the tabBarController referenced in the code above. And when I remove this block of code, the scrollsToTop works properly.
I think I need to adjust the container to include the TableViewControllers somehow. Any Ideas on how to do that?
The answer to my own question:
The problem appears to be that I had the left menu inside a navigation controller. So I abandoned that, and made a storyboard layout for the menu controller to use instead. And in that storyboard layout I added a navigation bar to cover up the black space that normally appears in this version of MFSideMenu.
So the new window setup in AppDelegate is...
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
UITabBarController *tbc = [storyboard instantiateViewControllerWithIdentifier:#"MainTabBar"];
//Then put get the left side menu controller, but inside of a navcontroller
SideMenuViewController *leftSideMenuController = [storyboard instantiateViewControllerWithIdentifier:#"SideMenu"];
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:tbc
leftMenuViewController:leftSideMenuController rightMenuViewController:nil];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
The scrollview problem in the other UIViewController turned out to be an Autolayout issue.
I have a series of views that are managed under a Navigation Controller. Is there a way to programmatically (in iOS5+) jump (push/pop) to different views? For instance, I have
NavigationController->RootViewController->DetailViewController1->DetailViewController2->DetailViewController3
How can I, say, jump from RootViewController to DetailViewController3, and then jump back to DetailViewController1?
Thanks.
You can try something like this.
Get your VCs from storyboard. (You have to set identifiers in storyboard)
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *DetailViewController1 = [storyboard instantiateViewControllerWithIdentifier:#"DetailViewController1Identifier"];
UIViewController *DetailViewController3 = [storyboard instantiateViewControllerWithIdentifier:#"DetailViewController3Identifier"];
Push VCs way you need.
[self.navigationController pushViewController:(DetailViewController1) animated:YES];
[self.navigationController pushViewController:(DetailViewController3) animated:YES];
Now, when you press "back" you'll see DetailViewController1.
I am developing an app that use MFsidemenu for the swipeBar.
My app consists of a loginController which is an uiViewController and after logging it change into an uiNavigationController.
MFsidemenu need this code running on the AppDelegate:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
UIViewController *leftSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:#"leftSideMenuViewController"];
[MFSideMenu menuWithNavigationController:navigationController
leftSideMenuController:leftSideMenuViewController
rightSideMenuController:nil];
The problem is how to change the second line of the code if the initialView is an uiViewController(Login) and after that, how to pass it to the secondViewController(MainMenu) which is an uiNavigationController?
In a shortway, I want the MFSidemenu to work only on the secondController, which is the main controller. Thanks!
Updated:
solved, by SpaceDust solution below :)
Question Update:
So the example of using MFSidemenu only limited to showing a sidemenu on the controller. The example sideMenuController exiled from any other segue on the storyboard. on the sidemenu I implemented uiTableViewController to navigate to another controller. So how to change MainMenuView with sideMenuController didSelectRowAtIndexPath? I hope my english good enough to represent my situation though. Thanks once again!
You need to present your uiViewController(Login) as a modal view controller if you dont want to side menu appear during login.
Create a login viewcontroller in storyboard, give it a storyboard id lets say LoginViewController . Dont connect that viewcontroller to anything on storyboard let it sit a corner by itself.
first create a global singleton variable where you check if user is logged in
then In your navigationcontroller's rootviewcontroller
-(void)viewWillAppear:(BOOL)animated
{
//this will present the login view if user is not logged in
if (isLoggedIn==NO) {
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"MainStoryboard"
bundle:nil];
LoginViewController *loginVC = [sb instantiateViewControllerWithIdentifier:#"LoginViewController"];
[self presentModalViewController:loginVC animated:YES];
}
}
in your login viewcontroller when login process is complete
change global singleton bool to isLoggedIn=YES
then dismiss your login view controller.
[self dismissViewControllerAnimated:NO];