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.
Related
To display mini view with controls for chromecasting video in app , root view need to be changed progrmatically. the below code need to be added to the storyboard.
// Wrap main view in the GCKUICastContainerViewController and display the mini controller.
UIStoryboard *appStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *navigationController =
[appStoryboard instantiateViewControllerWithIdentifier:#"MainNavigation"];
GCKUICastContainerViewController *castContainerVC =
[[GCKCastContext sharedInstance] createCastContainerControllerForViewController:navigationController];
castContainerVC.miniMediaControlsItemEnabled = YES;
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
self.window.rootViewController = castContainerVC;
But i made tabbar controller app , rootview intiated from storyboard. can somebody help me to change or modify the rootview to get miniView (container view) in tabbar application?
Changing root view when using tab view does not look mandatory thing to me just try adding the complete navigationController object itself on the tab.
By this way on any one of the tab is will have your mini view with controls.
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
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 want to add a navigation view controller prior to the user getting to the splitview controller. I have tried a few ways of changing the root controller when I want to go from navigation controller to splitview controller but I don't seem to be setting the delegate the right way when I do this.
Code WITHOUT nav view (works perfectly):
AppDelegate
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
UINavigationController *masterNavigationController = splitViewController.viewControllers[0];
MasterViewController *controller = (MasterViewController *)masterNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
Code with nav view prior to SplitView
AppDelegate
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController* rootController = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"dummy"];
self.window.rootViewController = rootController;
[self.window makeKeyAndVisible];
DummyViewController
AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];
appDelegateTemp.window.rootViewController = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
This takes me from the DummyViewController that I launched into, to the splitview controller which is the initial view controller in Storyboard. Which is fine however, when I do it this way none of the delegates get called. This is probably because when changing root controllers, it is not setting the delegates properly. How can I get this to work the right way?
It seems the only really non-hacking way to do it is to present a modal view over the split view in the detail view controller
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
DummyViewController *dummy = (DummyViewController *)[storyboard instantiateViewControllerWithIdentifier:#"dummy"];
[self presentViewController:dummy animated:NO completion:nil];
By setting animation to NO, the user does not see the split view loaded behind it.
I'm implememting a design based on the TabbedBanner example in the iAdSuite. I have a UINavigationController in the first tab. In that UINavigationController I have a view controller that simply has a button that pushes to another view controller. The pushed view controller is set to Hide Bottom Bar On Push in Interface Builder.
Here is the code where I'm setting up the UITabBarController.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:[[NSBundle mainBundle].infoDictionary objectForKey:#"UIMainStoryboardFile"] bundle:[NSBundle mainBundle]];
_tabBarController = [storyboard instantiateViewControllerWithIdentifier:#"TabBarController"];
_tabBarController.delegate = self;
FirstViewController *firstView = [storyboard instantiateViewControllerWithIdentifier:#"FirstViewController"];
UINavigationController *firstNav = [[UINavigationController alloc] initWithRootViewController:firstView];
_tabBarController.viewControllers = #[[[BannerViewController alloc] initWithContentViewController:firstNav], ];
self.window.rootViewController = _tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
Everything works except the TabBar does not get hidden when I push to the next view controller. I have tried hiding the TabBar using the Interface Builder check box as well as using nextViewController.hidesBottomBarWhenPushed = YES and neither way works.
If I remove the BannerViewController implementation, the TabBar hides exactly as it should.
It seems to me that the BannerViewController is interfering with the UINavigationController being able to hide the TabBar.
Is it possible to use Hides Bottom Bar When Pushed to hide the TabBar in this type of setup?
Thanks
Note: I realize that the code above only has one tab. I removed the other tabs for clarity.
I think this is happening because the BannerViewController itself is just a container viewController and it never actually pushes another view controller. The view controllers are pushed within the container.