I have this MonoTouch related question, but I think Objective/C programmers can help as well.
I have TabBarController with some tabs. I want my home viewController (which is added to tabBar) to appear without tabBar.
I thought the way to do it was to set HidesBottomBarWhenPushed of that controller to true.
homePage = new HomePageController();
homePage.HidesBottomBarWhenPushed = true;
homePage.TabBarItem = new UITabBarItem("Home", new UIImage("Images/Icons/home.png"), 0);
However, it seems that this works only in case of using TabBar with NavigationController, i.e. in case we actually push controllers.
I wonder if there is a way to do it just for simple viewControllers contained in tabBarController.
You can try to set the hidden property of the tab bar to YES. (or true in MonoTouch)
I found out that, in fact, you cannot cover tabBar area of tabBarController. You can set hidden property, just like Moshe said, or you can play with opacity as well but can't cover it with anything.
But there's a great alternate solution. You can use modal view, which always has higher index than regular controllers. Therefore, it will cover everything.
homePageContent.ModalPresentationStyle = UIModalPresentationStyle.FullScreen;
homePageContent.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical;
this.PresentModalViewController(homePageContent, false);
base.ViewWillAppear (animated);
Related
I'm working on a project that has two different sets of tabs that are presented based on certain conditions. My question is how to best present the two different sets of tabs via their UITabBarControllers.
Right now, the app is meant to launch with the default UITabBarController but when I want to switch, I'm confused as to how to best present the second UITabBarController and completely get the first UITabBarController off the memory stack. And, vise versa. Would it be the same to switch back to the first UITabBarController?
This is the code used as of right now to switch from the first to the second.
let secondaryTabBarController = SecondaryTabBarController()
let secondaryTabs = UINavigationController(rootViewController: secondaryTabBarController)
UIApplication.shared.keyWindow?.rootViewController = secondaryTabs
To address your concern about memory, the method you suggested is completely fine in that regards and does not inherently cause any memory leaks.
And yes, if you want to switch back to the first tab bar controller you can use the same method, creating a new instance of your first tab bar controller and setting it as the window's root view controller.
You can animate the transition by using UIView.transition(with:duration:options:animations:completion:), which has some built-in transition animations.
Alternatively you can use setViewControllers(viewControllers:animated:) on UITabBarController if you just want to change the tabs, or if you want to preserve selection.
I have a standard view with a bar at the top for navigation. I also have a Monotouch.Dialog set in it's own source file. I've looked around for a solution to this, but can't seem to find a definitive answer on how to add a MTD to a normal view.
Is there a simple way to do this?
You instantiate the DialogViewController and add its View to your view.
DialogViewController vc = new DialogViewController(null);
// Build and set your root here.
vc.View.Frame = new RectangleF(20f, 20f, 280f, 560f);
this.View.AddSubview(vc.View);
You might have issues with ViewController methods (i.e. rotation methods) not being forwarded correctly in this scenario, so be sure to test.
This is extremely ugly though and should only be used when you absolutely must have the Dialog view nested.
In a scenario where the DialogViewController is displayed in full screen (with or without the navigation bar), a more elegant solution is to use a UINavigationController as the root view controller in your app (which would take care of the navigation bar for you), and either setting or pushing the newly created DialogViewController onto it.
I'm making an app with interface builder using storyboarding.
I want to have a tab bar where no item is selected. This can be accomplished by setting
TabBar.SelectedItem = null;
But if you try to do that, you get the following error:
'Directly modifying a tab bar managed by a tab bar controller is not allowed.'
So I can't use the standard UITabBarController. I've created a custom UIViewController, and added a UITabBar. Switching between tabs is working fine, and having no selection is also working as it should.
But I have no idea how to show my other view controllers from my custom view controller with the tab bar. Remember that I'm using interfacebuilder, so I can't just create my view controllers in code as new objects and add them to the view. (as suggested in UITabBar funcionality without UITabBarController)
So how do I show my own views without using the UITabBarViewController?
Edit: Still haven't found a solution, but I did a hacky fix. Simple create an other tab bar and place it on top of the original tab bar. Listen to those events and use SelectedIndex to change the view displayed. Then add some function that will select / deselect the items on your own tab bar.
In fact, even if you design your others UIViewControllers from IB, you can instantiate them from code. You'll probably have to play a bit with frame and autoresizing properties to make them fit the part of your main view you want them to display inside, but it's possible.
So, knowing that, a simple solution is to create a simple UIView (we'll call it 'tabFrame') in your main UIViewController, which fill the screen from the top of your UITabBar to the top of the screen; instantiate the UIViewController corresponding to your tabs and add their view as subview of tabFrame. Now you just have to catch item selection from tabbar to hide or show the desired subviews.
Hope I'm clear enough, else don't hesitate to question!
EDIT: pointed out this morning that in storyboarding context, you can effectively instantiate viewControllers / scene from code, but for not loosing designer settings it must NOT be done through directly calling their constructors, but through StoryBoard.InstantiateViewController("vc_identifier") calls, after having set identifiers to VCs in storyboard editor.
See http://docs.xamarin.com/ios/recipes/General/Storyboard/Storyboard_a_TableView for example
I have been coding in iphone platform for about a few months. One thing I am still to understand is in which method exactly should I set the navigation bar/toolbar/barButtonItem hidden.
In my project sometimes I set in - (void)viewDidLoad, sometimes I set in - (void)viewWillAppear:(BOOL)animated. Sometimes I set it from where I push the navigation controller.
I think I am not understanding the basics correctly. If one way is not working, I try the other way and somehow it works.
If I am to hide the toolbar or barbuttonitem in navigation controller, where exactly should I set that.
Edit:
If I am pushing a new navigation controller, in which I want my toolbar hidden, where should I set it hidden. Similarly, when I pop it, I want the the toolbar to be shown, where should I set the toolbarHidden property to 'NO'.
Similarly, I have a navigation controller, sometimes it needs to show the toolbar and sometimes it needn't, where should I check the condition for this case.?
You should set this property before the pushing the view Controller and don't need to set No at pop. E.g see the following link:
hiding tabbar on table view cell click
I am sure this is very simple, yet I am stuck...
I have created an application and added UITabViewController (dragged in from the library in Interface Builder. My application has 3 different views, clicking on appropriate tab brings the different view. So far so good.
I want to convert one of the views to be a UINavigationController: basically a table with the option to delete rows (so UINavigationController would need to have a button "Edit" on top).
I saw many samples which would do either 1 or 2, but not both.
How would I combine it, keeping in mind that I have used provided UITabViewController and did not added UITabBar directly to the view.
Thanks
If you are using Interface Builder, you should be able to just drag and drop a navigation controller into your tab bar controller as a child controller. The next tab bar item should be generated for it automatically from that.
You can also do this programatically by just creating however many UINavigationControllers you need in an array and assigning that to the uitabbarcontroller appropriately.
I actually don't like this method of combining the UINavigationController and UITabBarController since the tab bar controller must always be visible, which can be really confusing sometimes.
Instead, I recommend you make your own custom UITabBarController (Tab bar controller inside a navigation controller, or sharing a navigation root view) which you add to the navigation controller. I personally don't know why Apple didn't do this; hopefully this is the standard way in 4.0 :)