One instance of navigation bar in every tab - ios

I've been struggling this problem for several days. In my application I have tab bar controller with UINavigationViewControllers inside. I want every navigation bar in every navigation controller to look exactly the same depending on user actions and app state.
For example: if user logged in to my app in first view controller, app sets his name in navigation bar and sets navigation bar into logged in state. Then when user selects other tab item, I want to set this logged in state of navigation bar from first view controller to other view controllers. I've tried to use singleton but with no effect.

Seems like you have to do 2 things:
Set the current settings while init the UIViewController
Update all initiated Controllers after state changes
to 1:
create a class with
#interface UIViewController (UINavigationController)
- (UINavigationController*)wrapWithNavigationController;
#end
#implementation UIViewController (UINavigationController)
- (UINavigationController*)wrapWithNavigationController
{
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:self];
// your customizations
navigationController.navigationBar.barStyle = UIBarStyleBlack;
[...]
return [navigationController autorelease];
}
#end
you can call it UIViewControllerAdditions for example.
to 2:
use the NSNotificationCenter for updates :)

Do you really have multiple UINavigationControllers, or do you just want to use the navigationBar for the same actions and functionality in every tab?
If you just want to have the bar, you could also use an UINavigationController as your apps rootViewController and then the UITabBarController as a childViewController of your UINavigationController.

Related

ios: TableViewControl in TabViewControl the navigation bar overlaps table view

The root View View controller is Navigation controller and its first level is a TabViewController.One of the tab item is a TableViewController.
Here is the relationship:
However the navigation bar overlap the table view:
I have also set simulated metrics,So what can be the problem??
Thanks for any help.
Simulated metrics are just that, simulated. They do not actually apply to the compiled product.
To fix this, I find it easiest to set the edgesforextendedlayout with the various values of edge values. Usually all but the top.
The rootViewController should be the UITabBarController. Follow this code:
1.Make the UITabBarController the rootViewController in the application delegate or in your main.storyboard set it as the initial View Controller.
2.In the UITabBarController.m place this code there to create the UINavigationController with a UIViewController embeded inside of it.
//Inside UITabBarController.m
- (void)viewDidLoad {
[super viewDidLoad];
UIViewController *vc = [[UIViewController alloc]init];
UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:vc];
self.viewControllers = #[navCon];
}
Get rid of the navigation controller in the beginning and, instead, embed the tableviewcontroller inside a navigation controller.
(Select the view controller -- Click "editor" > "embed in" > "navigation controller").
Make sure the tab bar controller is the root view controller as well
This will also fix the overlapping issue

Navigation Bar & Navigation Toolbar NOT from App Delegate

I'm new to xcode ios 7.
I've struggling a lot with navigation controls building app for iPhone ios7.
I don't want to use storyboard. I prefer to do it programmatically.
What i am trying to do.
I know how to create NavigationBar & Navigation Toolbar via AppDelegate.m
But if it's possible i don't want to do it, because let's assume i want in FirstViewController to show just simple button "Go to Second View Controller" (No Navigation Bar or Toolbar here).
And now in SecondViewController i want to create Navigation Toolbar (bottom) with 4 different tabs linking to ViewControllers!
But the trick is, i want to maintain different Navigation Bar (top) for every ViewController (as you can see in this screenshot).
Here is my Xcode Project File
And here is screenshot form Fancy app showing what i am trying to achieve.
Thanks a lot in advance!
Just to give you an idea, When you tap the button on your first view controller, you can create a UINavigationController and set your second view controller as its root view controller. This way, your first view controller remains no nav bar view and the second view controller holds a Navigation controller. Try something like below:
-(IBAction)goToSecondVC:(id)sender // An action for the button in your first VC
{
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil]; //Init with second view controller
UINavigationController *secondNavVC = [[UINavigationController alloc] initWithRootViewController:secondVC]; // create a navigation controller and set the root as your second view controller
[self presentViewController:secondNavVC animated:YES completion:nil]; // and then present it with anim or no anim..
}

Tab bar controller inside a navigation controller, how to push new viewcontrollers to the tabcontroller?

Design requirement:
Show a list of items the user can pick from
After having picked an item, bring the user to a new view with a back button. The new view should contain a list of tabs at the bottom that are not present in the first screen
When clicking an item in the tabs, a new screen should appear with a back button and the tabs should still be visible at the bottom.
Clicking a tab should take the user back up the hierarchy to #2. Not to the first screen.
I have tried following structure:
UINavigationController
UIViewController with a UITableView
UIViewController with a UITabBar (like here http://www.wiredbob.com/2009/04/iphone-tweetie-style-navigation.html)
and also
UINavigationController
UIViewController with a UITableView
UITabbarController
Both cases work fine with displaying the UITabBar, but when I click an item in one of the tabs and push a new UIViewController, then the tabs at the bottom disappears. I want the tabs to remain in place for all pushed UIViewControllers that occurs inside a tab of the UITabBarController.
A related question is this one but it doesn't deal with the problem of pushed viewcontrollers inside a tab:
Tab bar controller inside a navigation controller, or sharing a navigation root view
Do I need to change the rootcontroller to the UITabController? Anyone actually implemented this?
Here is the correct structure:
UITabBarcontroller (UIWindow's rootViewController)
->UINavigationController (first tab)
-->UIViewController
->UINavigationController (second tab)
-->UIViewController
It sounds like you want to change the layout of your view hierarchy to accommodate your requirements. You should present your view controllers as such:
UITabBarController -> UINavigationController -> UIViewController
In your app delegate, you can implement this programmatically using something along the lines of:
UIViewController *viewControllerOne = [[[UIViewController alloc] init] autorelease];
UINavigationController *navigationControllerOne = [[[UINavigationController alloc] initWithRootViewController:viewControllerOne] autorelease];
UIViewController *viewControllerTwo = [[[UIViewController alloc] init] autorelease];
UINavigationController *navigationControllerTwo = [[[UINavigationController alloc] initWithRootViewController:viewControllerTwo] autorelease];
UITabBarController *tabBarController = [[[UITabBarController alloc] init] autorelease];
[tabBarController setViewControllers:[NSArray arrayWithObjects:navigationControllerOne, navigationControllerTwo, nil]];
[[self window] setRootViewController:tabBarController]
I haven't checked the above, it's just written from memory but should do what you require as an example.
Using this format, you can push any additional view controllers on to the navigation controller stack without your tab bar disappearing.
If you want to push this view hierarchy without having the tab bar controller as your root view controller, simply push the tab bar controller instead of setting it as the root view controller in the app delegate.
Hope that helps!

Access a tab element in tab bar controller and change value

How do you access an element in a tab bar controller and change its value? For instance i want to access a particular view controller in a tab bar controller and change a property in the view controller. Been stuck with this for a while. I have called tab bar init with nib name and initliased the tab bar. Now i need to know how to access one view in it. I tried
UITabBarController *newTabBar = [[UITabBarController alloc]initWithNibName:#"PlaceTabBarControllers" bundle:nil];
[newTabBar.selectedViewController setView:listViewController.view];
but this doesnt work.
UIViewController *viewController = [newTabBar.viewControllers objectAtIndex:0];

How to Push A view with TabBarController as Root

I'm starting out with iOS Development.
Currently, I've implemented a TabBarController that nests 2 Views, one of which has a TableView within in.
I'm trying to get the table view to Push another view when DidSelectRow is called.
What I am trying to do is similar to the AppStore in the Search Tab.
I.E:
When you find the App you want you tap on the table row - then the search bar fades away and the Navigation bar fades in, revealing more detail.
Right now I'm trying this:
self.nav = [[UINavigationController alloc] initWithRootViewController:rootVC];
nav.delegate = self;
self.detailView = [[detailView alloc] initWithNibName:#"detailView" bundle:nil];
[nav pushViewController:self.detailView animated:YES];
Where rootVC is the viewController in my secondView.
This does nothing. I've called NSLog to make sure that the method is being called, and it is.
Any help is greatly appreciated.
Thanks!
Do you have a navigation controller in the app? One way to achieve the navigation controller with tab bar controller is to add navigation controller for each tab bar item . Then make the root view controller of the navigation controller one of your 2 views controllers.

Resources