BannerViewController interferes with hidesBottomBarWhenPushed - ios

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.

Related

How to skip the root view and go directly to displaying the second view in a UINavigationController hierarchy?

I am making a messaging app on ios that will have multiple folders for different types of messages. I will be using a navigation controller structure and would like the root view to be where the user can choose which folder to view. However, when I first segue to the navigation controller I would like the inbox folder view to display directly (ie. bypass the root view). Apples mail app has a similar structure (launches inbox when it opens). how can I do this?
It really depends on how the relationship is between the first view controller and the second view controller. If you want to do something like this, why don't you put your second view controller as the root controller of the UINavigationController.
Anyway, if you still want to do it the way you describe, you can just direct to the second view controller using the viewDidLoad method from your root view controller. But, it will make the UI looks clumsy.
try to use this code :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIStoryboard *board = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ViewController *controller1 = [board instantiateViewControllerWithIdentifier:#"firstView"];
UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:controller1];
SecondViewController *secondView = [board instantiateViewControllerWithIdentifier:#"secondView"];
[controller1 addChildViewController:secondView];
[self.window setRootViewController:navController];
return YES;
}
Hope this will help you.
Write this code in didFinishLaunchingWithOptions of AppDelegate.m
UIStoryboard *MainStoryboard = [UIStoryboard storyboardWithName:#"Main"
bundle: nil];
UINavigationController *controller = (UINavigationController*)[MainStoryboard
instantiateViewControllerWithIdentifier: #"YourStoryBoardID"];
NeededViewController *need=[MainStoryboard instantiateViewControllerWithIdentifier:#"YourStoryboardID"];
[controller setViewControllers:[NSArray arrayWithObject:need] animated:YES];
self.window.rootViewController=controller;

UISplitViewController: Does not show up when setting it up pragmatically

I am trying to setup a splitviewcontroller using storyboards. The code below is what I have so far. However, it is showing a black screen. I have a storyboard name Main. I have two viewcontrollers in the storyboard. I read how to do this from an article, but can't get it to work. I must be missing something small. Any help is appreciated.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main"
bundle:nil];
ViewController *firstVC = [sb instantiateViewControllerWithIdentifier:#"ViewController"];
ViewController1 *secondVC = [sb instantiateViewControllerWithIdentifier:#"ViewController1"];
CGRect frameFirstVC = firstVC.view.frame;
frameFirstVC.size.width = 100;
CGRect frameSecondVC = secondVC.view.frame;
frameSecondVC.size.width = 100;
UISplitViewController* splitVC = [[UISplitViewController alloc] init];
splitVC.viewControllers = [NSArray arrayWithObjects:firstVC, secondVC, nil];
[self.window addSubview:splitVC.view];
[self.window makeKeyAndVisible];
return YES; }
You shouldn't add the split view controller's view as a subview of your window directly. Instead, set the window's rootViewController property:
self.window.rootViewController = splitVC;
In addition to configuring the view hierarchy, this sets up additional state and layout information for the app to properly display and use the split view controller.
(I should point out that instead of writing any of this code, you could put the split view controller in your storyboard, mark it the initial view controller, then use that storyboard as your app's main interface file. That's a bit of a bigger change, though.)

How can I load a view "properly" iOS

My app consists of a navigation controller and view controllers. Some parts of my UI is done on storyboard and some are initiated from code (in viewDidLoad). My goal is to load childViewController X (consists of a back button, nag bar, label and table) when the app is launched from a push notification "properly" through this method in appDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
This might be a simple question to you guys but I've asked several questions the pass few days (you can look at my questions history). After trying several methods, my app either:
crashes
loads without navigation bar
loads with navigation bar but no label (back button does not work)
loads with navigation bar but with black screen underneath
Only the tableView is dragged onto storyboard. The navigation bar is inferred but I have code that dictates its back button and title. The rest is all done through code in the .m file.
I know people have asked this question before but none of the methods worked. How can I load this childViewController properly through a push notification?
EDIT/UPDATE:
My code so far:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController* firstVC = [mainstoryboard instantiateViewControllerWithIdentifier:#"NotificationsViewController"];
[self.window.rootViewController addChildViewController:firstVC];
[(UINavigationController *)self.window.rootViewController pushViewController:firstVC animated:NO];
self.window.rootViewController.childViewControllers);
}}
Error Code:
'-[SWRevealViewController pushViewController:animated:]: unrecognized selector sent to instance 0x14575f20'
SWRevealViewController is my library for my sidebar menu view controller.
UPDATE2:
I've also tried this method:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:#"NotificationsViewController"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = initViewController;
[self.window makeKeyAndVisible];
This loads the correct viewController but without a navigation bar.
Try this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(dictionary != nil) {
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *firstVC = [mainstoryboard instantiateViewControllerWithIdentifier:#"NotificationsViewController"];
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
// Navigation already created
if(navigationController) {
[navigationController pushViewController:firstVC animated:NO];
// Navigation not created
} else {
UINavigationViewController *navigationController = [[UINavigationViewController alloc] initWithRootController:firstVC];
[self.window setRootViewController:firstVC];
[self.window makeKeyAndVisible];
}
}
return YES;
}
You had some problem in your code:
You need to have a UINavigationController in order to have a navigation bar and manage the push/pop actions, so your window root controller should be a UINavigationController.
If you need to initialize a UINavigationController the best and simple way is to initialize it with a root controller directly, so leave the push/pop for user actions: an application has always a root controller, so why don't you create it immediately?
The "addChildController" is another thing: it is used to create custom container controller, it means that you have to implement all the business logic manually. I suggest you to use it only if you are experienced enough, since it could be difficult - Cocoa has enough components to leave it for a small set of applications.
You are using a third part controller, the "SWRevealViewController". They should have an example project, you can try to "copy" it and them customize it for your own purpose.
Let me know if your code works well, otherwise post the new error and I'll try to help you

Initiating a view properly with navigation bar

My app consists of a navigation controller and view controllers. Some parts of my UI is done on storyboard and some are initiated from code (in viewDidLoad). My goal is to load childViewController X (consists of a back button, nag bar, label and table) when the app is launched from a push notification "properly" through this method in appDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
This might be a simple question to you guys but I've asked several questions the pass few days (you can look at my questions history). After trying several methods, my app either:
crashes
loads without navigation bar
loads with navigation bar but no label (back button does not work)
loads with navigation bar but with black screen underneath
Only the tableView is dragged onto storyboard. The navigation bar is inferred but I have code that dictates its back button and title. The rest is all done through code in the .m file.
I know people have asked this question before but none of the methods worked. How can I load this childViewController properly through a push notification?
My code so far:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController* firstVC = [mainstoryboard instantiateViewControllerWithIdentifier:#"NotificationsViewController"];
[self.window.rootViewController addChildViewController:firstVC];
[(UINavigationController *)self.window.rootViewController pushViewController:firstVC animated:NO];
self.window.rootViewController.childViewControllers);
}}
Error Code:
'-[SWRevealViewController pushViewController:animated:]: unrecognized selector sent to instance 0x14575f20'
SWRevealViewController is my library for my sidebar menu view controller.
I've also tried this method:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:#"NotificationsViewController"];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = initViewController;
[self.window makeKeyAndVisible];
This loads the correct viewController but without a navigation bar.
It looks like you have your rootViewController set to a custom controller of type SWRevealViewController. If you want to call pushViewController:animated: on rootViewController, it must be a UINavigation controller. Currently you are calling it on a controller that does not respond to that message.
In your Storyboard make sure you drag a UINavigationController onto the canvas and move the root-view-controller arrow in InterfaceBuilder to point to it. Then load whatever ViewController you want into the navigationController. (i.e. your code at the top of your question should work).

MFsidemenu disables scrolltotop table view

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.

Resources