I have put one global tabBarController in iphone app that I have been working on.
But in one of my screen I needed to put the local tabBar which is different from the global tabBarController.
I have done it in two ways:
1) Hiding the global tabBar by self.tabBarController.tabBar.hidden = yes; and putting local tabBar in place of it in the view. But the frame of tabBar is showing blank white.
2) Tried by adding the local tabBar as subview of global tabBar which worked but after screen is unloaded its not removing the local tabBar though applying [localTabBar removeFromSuperView];
Thanks in advance..
Global tabBarController:
tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects:ActivityTabnav,nav2,privateChatnav,ExploreTabnav,nav3,tempTabnav, nil];
localtabBar is a tabBar on view xib of viewController.
in vIewDidLoad >
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
[window addSubview:self.tabBar];
in vIewDidUnLoad >
[self.tabBar removeFromSuperview];
Previously I tried to add self.tabBar to self.tabBarController.tabBar as a subView which persisted the local self.tabBar in other screens.
Thank you...
The cleanest way I've found to do this is to set the hidesBottomBarWhenPushed property of your view controller, then place it inside a UINavigationController (hiding the navigiationBar if you don't need it). This will hide the UITabBarController's UITabBar without leaving a white space.
You'd then put the local UITabBar directly into the UIViewController's view;
Another possibility would be to hide the UITabBarController's UITabBar, then add the local UITabBar to as a subview of UITabBarController's view. Of course you'd have to remove from superview when needed.
One way is to add TabBar on Window. But be sure that you handle is correctly. You can add it on window by taking the Current Window object and then add TabBar onto it... as below...
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
[window addSubview:tabbar];
this could be one option but handle it carefully...
Related
I am in the process of making my first iPhone app with storyboard in Xcode and am stuck. My main screen has a view controller called MemberViewController, which is the home screen. This screen has a UIView that is smaller than the view controller called mainContent.
So basically, I want to be able to load different view controllers (all the same size as the UIView) inside the UIView.
MemberViewController (home page)
-mainContent (UIView)
GetStartedViewController (separate view controller that I want to show inside the UIView)
ProfileViewController (separate view controller that I want to show inside the UIView)
For example, I want the GetStartedViewController to have a button that I can press to switch to the ProfileViewController. The view controllers need to be able to replace each other inside the mainContent UIView.
Thank you so much in advance for your help. If there's an easier way to do this, please let me know.
I use this technique a lot actually. My typical setup of a root UIViewController (you call it memberController) has a view with a UITabBar at the bottom, and then another UIView (you call it mainContent) which contains the rest of the space above that bar.
memberController stays on the screen all the time. Inside of mainContent, add a UINavigationController and initialize it with your first content-carrying GetStartedViewController. When you want to switch tabs on your tab bar, send the appropriate message to this UINavigationController and the views will change inside.
HINT: say your UINavigationController is called navController - you can get rid of the navigation bar (blue one at the top) by sending the message [navController setNavigationBarHidden:TRUE];
EDIT: The code you requested looks like this. This adds a nav controller to a window's view in the applicationDidFinishLaunchingWithOptions method. Instead of window, just do this same thing on your view controller in the viewDidLoad.
window and navController are both properties
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.navController = [[UINavigationController alloc] initWithRootViewController:[YourViewController new]];
[self.navController setNavigationBarHidden:YES];
[self.window addSubview:self.navController.view];
[self.window makeKeyAndVisible];
Hope this helps!
I would like to add a bottom bar in a view and then keep it there while I browse several views (each one with a nab bar). I hope it will follow Apple guidelines (I already know that only the nab bar is recommended) or at least the app is accepted.
For doing so, I have added a UIView to the application window. This UIView contains a UITabBarController which contains the navigation controllers (each one as a rootviewController) of each one of the items of the bar:
UIWindow *window=[[UIApplication sharedApplication] keyWindow];
MyUIViewController *mv=[[MyUIViewController alloc]init];
UINavigationController *navd = [[UINavigationController alloc] initWithRootViewController:mv];
navd.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"MyItem" image:[UIImage imageNamed:#"myImage.png"] tag:0];
NSMutableArray *controllers = [[NSMutableArray alloc] init];
[controllers addObject:navd];
UITabBarController *tbarController=[[UITabBarController alloc] init];
tbarController.viewControllers = controllers;
tbarController.customizableViewControllers = controllers;
UIView *vistaBarraInferior=tbarController.view;
[window addSubview:vistaBarraInferior];
[window makeKeyAndVisible];
It works, but my problem appears when I would like to go back and exit the ivies with UITabBarController. If I write:
[self.tabBarController.view removeFromSuperview];
[self.parentViewController.navigationController popViewControllerAnimated:YES];
The tab bar is removed from the current view, but I canĀ“t reach the previous view (the root view I had had before doing anything), because I have overwritten it with the 'initWithRootViewController'.
Is it any other way to make it easier or make this work out?
Thanks in advance.
If you want to combine tab bar and navigation bar you must use tab bar as a root and for each tab item add one navigation controller. You can't do it in opposite way as tab bar must be always root.
I am not sure what do you want achieve with bottom bar. Whether it should serve as a tab bar or toolbar. Remember if you use tab bar then each tab will have its own stack of views managed by navigation controller. On the other hand toolbar is related to one view.
If you want to create something like overlay toolbar - something that is always on top of views even if they are animating in and out - you need to choose different solution.
For example you can create your own controller that will display your toolbar at bottom and some container view which content will be managed by navigation controller.
You should use a tabbarcontroller with array of navigation controllers. See apple sample code here for example.
I went through your code and it does not look right on different levels. For example you are calling initwithviewcontroller but passing a uiview. That is not correct.
If I rewrite this code in other way:
UITabBarController *tabBar=[[UITabBarController alloc]init];
tabBar.title=#"MyTitle";
NSMutableArray *items=[[NSMutableArray alloc]init];
MyUIViewController *ld = [[MyUIViewController alloc] init];
[tabBar addChildViewController:ld];
UITabBarItem *tabItem=[[UITabBarItem alloc]initWithTitle:#"Item1" image:[UIImage imageNamed:#"myImage.png"] tag:0];
[items addObject:tabItem];
[tabItem release];
[tabBar setToolbarItems:items];
[self.navigationController pushViewController:tabBar animated:YES];
The result is that the tab bar at the bottom is empty. Have I forgotten to write anything else to show the tab bar item?
If I add a second item, only its title is shown, but neither its image nor anything related to the first item is shown.
I have TabBar View combined with Navigation View.
Structure like this:
delegate -> TabBar -> (many) Navigation Views -> (many for each) Controller Views.
I want show one view (config) before any other view. I want this view without Bars and Navigation Controlls.
It is possible? How I can do this ?
Thanks for help
Yes, It's very possible. In your applicationDidFinishLaunching method, simply make your config view the root view controller like this:
UIViewController *configVC = [[ConfigVC alloc] initWithNibName:#"ConfigVC" bundle:nil];
[[self window] setRootViewController:configVC];
[configVC release];
and then, some later time when you are ready to show the tab bar, do:
[[self window] setRootViewController:tabBarViewController];
UPDATE:
You can access the application delegate like this: [[UIApplication sharedApplication] delegate];
After this, you can cast it to your app delegate to avoid any warnings, and then call the method that loads the tab bar...
As far as i can understand, you have a tabbar based application and you want to display a view in the start of your application, You can just display that page as modalviewcontroller and hide navigationbar and status bar.
So I'm building an app and I am running through a few ViewControllers that don't need to know about each other, so I start off switching through views like so...
// remove the previous view in order to load in the new view
NSArray *sViews = [self.view subviews];
[sViews makeObjectsPerformSelector:#selector(removeFromSuperview)];
// create the new view, in this case the user wishes to
BaseViewController *baseVC = [[BaseViewController alloc] initWithNibName:#"BaseViewController" bundle:[NSBundle mainBundle]];
self.baseViewController = baseVC;
[baseVC release];
// add the newly created view to the screen
[self.view insertSubview:baseViewController.view atIndex:0];
The above is the view controller that I want the navigation controller to reside in. So within the .m of this view controller I created a UINavigationController as a member variable and named it navController. I then tried implementing a UINavigationController using the code below.
UIViewController *control = [[BusinessDisplayViewController alloc] initWithNibName:#"BusinessDisplayViewController" bundle: nil];
navController = [[UINavigationController alloc] initWithRootViewController:control];
[self presentModalViewController:navController animated:YES];
The problem I'm running into is two fold. First, when the BusinessDisplayViewController (below) is loaded there is a 20 pixel or so gap between my mapView and tableView that isn't there when I was loading it using insertSubview: not sure why that would be. Second, once I'm in BusinessDisplayViewController.m I'm not sure how to access the navigationController created in BaseViewController. Could someone explain why my view would be effected, how I could access the navigationController or if I'm even going about this the right way.
UINavigationController is designed for use in one of three possible contexts on iPhone:
As the app's root view controller, with its view added as a subview of the app's window.
As one of the viewControllers of a UITabBarController.
Presented as a full screen view controller via presentModalViewController:animated:.
In your case, the UINavigationController has configured itself for presentation as a subview of the window. This is why you see the 20 pixel gap at the top. Since the window object underlaps the status bar, UINavigationController offsets the position of its navigation bar by 20 pixels (or more, if you're on a phone call).
The standard way to use UINavigationController as your root view controller is to construct it as a property of your app delegate in application:didFinishLaunchingWithOptions:, and add its view as a subview of the window. Then within any view controller you push onto your navigation stack, you can access the navigation controller object using self.navigationController.
Usually, you want your UINavigationController to be at the root level, Is there a specific reason for having your app setup this way? To answer your question though, you can access the variable by setting a property for it, then using the dot notation: baseVC.navController.
For the 20 pixel space problem, post your BaseViewController view related code. It is probably a bounds vs frame issue.
I have a UIImagePickerController that is shown
[self presentModalViewController:self.picker animated:NO];
Then later on the code, I allow the user to display a preference panel :
PreferencesController *nextWindow = [[[PreferencesController alloc] initWithNibName:#"Preferences" bundle:nil] autorelease];
UINavigationController* navController = [[[UINavigationController alloc] initWithRootViewController:nextWindow] autorelease];
[self presentModalViewController:navController animated:YES];
At this point, the new controller raises on the screen, but don't go to the top.
Some space is left "transparent" at the top (I can see the camera view behind), and the bottom of the view is hidden out of the screen. The space I am talking about is about a status bar height. The status bar is not present on the screen.
The navigation controller is hidden :
self.navigationController.navigationBarHidden = YES;
There is a toolbar at the top of the view. Nothing special into the view.
The height of the view is defined at 480. All simulated element are set off in IB.
The autoresize properties are all set on.
I had a previous xib (I rebuilt it from scratch) that worked very well. I don't see what I missed on this one (I have only changed the xib, that replaces the previous one).
I've cleaned the cache to be sure there was nothing left. No change...
I've deleted everything in the new view to prevent some conflicts. No change...
What did I miss ? How could I remove this empty space ?
Try presenting the second modal view controller (the preferences one) from self instead of self.picker
ModalViewController loading on top of another Modal
Edit:
Try setting wantsFullScreenLayout = YES
After some searches and some other problems, I've found a final solution to the problem through this question
I had to call :
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
at the application start.