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];
Related
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
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..
}
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.
I am a beginner in programming in iOS. I have a iOS application that has two classes(with xib), firstviewcontroller and secondviewcontroller. I want to add a tab bar to switch between these view controllers. if I for example add a tab bar to the first view, how to connect the views to the tab bar? Its just there, doing nothing..
Try Look into this url , this will help.
http://www.amateurinmotion.com/articles/2009/01/24/creating-uitabbarcontroller-based-app-using-interfacebuilder.html
This assumes that you want the tab bar as the main interface of your app.
In your app delegate, create a subclass of UITabBarController:
UITabBarController *myTbc = [UITabBarController alloc] init];
Create instances of your two view controllers and add them to an NSArray
NSArray *tabsArray = #[firstVC, secondVC];
Set that NSArray as the viewControllers property of the tab bar controller
[myTbc setViewControllers:tabsArray];
Set the tab bar controller as the app's root view:
self.window.rootViewController = theTbc;
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!