i have been trying to put two controllers in the Container Controller.
First Controler
1) Just a View Controller with Few buttons
2) UITabBarController.
Below is the code snippet..
tabc = [[UITabBarController alloc] init];
hvc = [[HeaderViewController alloc] initWithNibName:#"HeaderViewController" bundle:nil];
[self addChildViewController:hvc];
[self.view addSubview:hvc.view];
[hvc didMoveToParentViewController:self];
bvc = [[BodyViewController alloc] initWithNibName:#"BodyViewController" bundle:nil];
bvc1 = [[Body1ViewController alloc] initWithNibName:#"Body1ViewController" bundle:nil];
UITabBar *tabBar = tabc.tabBar;
UITabBarItem *tabBarItem1 = [ tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [ tabBar.items objectAtIndex:1];
tabBarItem1.title = #"fruits";
tabBarItem2.title = #"vegs";
tabc.viewControllers = #[bvc,bvc1];
[self addChildViewController:tabc];
[self.view addSubview:tabc.view];
[tabc didMoveToParentViewController:self];
Problem:
In the tab view controller, only one tab is visible at a time [ i.e.: First tab ]
NOTE: My mistake, it shows both the tab, but the table name, or boundary of the tabs
are not visible. it shows as if the same tab. How to solve this issue ?
What is the quirk i need to be aware of ?.
It is a strange quirk that has bitten many. Tab bar controllers can only be the root controller and cannot be a child to the container. This is in apple's docs here: https://developer.apple.com/library/ios/documentation/uikit/reference/UITabBarController_Class/Reference/Reference.html
The section of interest is "The Views of a Tab Bar Controller"
The weird part is it can look like it works ok, but strange behaviors will crop up here and there.
Related
I am using am SWRevealViewController in my iOS 8.2 app. It works perfectly fine, but when my view displays though it a frosted navigation bar hangs around at the top of the screen, under the status bar. It is covering my background image, and I haven't found an easy way to remove it.
mainView = [[ViewController alloc] init];
sideMenu = [[MenuController alloc] init];
UINavigationController * frontViewController = [[UINavigationController alloc] initWithRootViewController:mainView];
UINavigationController * rearViewController = [[UINavigationController alloc] initWithRootViewController:sideMenu];
revealController = [[SWRevealViewController alloc] initWithRearViewController:rearViewController frontViewController:frontViewController];
revealController.delegate = mainView;
I searched through the SWRevealViewController code and didn't find anything obviously related to it. I tried commenting out suspicious sections of code and viewing the result. I hid the status bar. Nothing touched it.
I have tried a few things...
[frontViewController.navigationController setNavigationBarHidden:YES];
frontViewController.navigationController.navigationBar.frame = CGRectZero;
[frontViewController.navigationController.navigationBar setHidden:YES];
[revealController.navigationController setNavigationBarHidden:YES];
revealController.navigationController.navigationBar.frame = CGRectZero;
[revealController.navigationController.navigationBar setHidden:YES];
[revealController.navigationController.navigationBar setBounds:CGRectZero];
...to no effect.
As your front view is mainView you will be using
[mainView.navigationController setNavigationBarHidden:YES];
I hope this helps.
Upon completion of this question, I tried one final test.
[mainView.navigationController setNavigationBarHidden:YES];
This worked. It would appear that something in the process of embedding the mainView in the SWRevealViewController caused the navigation bar in the mainView itself to become visible, even though by default it was not.
I have a requirement where I need to slide the view but thats inside a UITabBarController.
Does any one tried doing that ? ECSlidingViewController works perfect if I make it rootViewController but I want that in UITabBarController.
I tried setting the ECSlidingViewController as one of the view controllers for the UITabBarController but it keeps crashing after the first swipe or some times it goes in infinite loop
Below is my code
myWorkController = [[TaskWorkViewController alloc] initWithNibName:#"WorkViewController_iPhone" bundle:nil]; // This is the controller where I have my specific logic
myWorkNavController = [[[UINavigationController alloc] initWithRootViewController:myWorkController] autorelease]; // setting the myWorkController to UINavigationController as I need to navigate from this view controller to different view on specific actions
//SlidingviewController setup
self.slidingViewController = [ECSlidingViewController slidingWithTopViewController:myWorkNavController];
self.slidingViewController.topViewController = myWorkNavController;
[myWorkNavController.view addGestureRecognizer:self.slidingViewController.panGesture];
self.slidingViewController.anchorRightPeekAmount = 100.0;
myWorkController.slidingViewController = self.slidingViewController;
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = #[ self.slidingViewController, createNavController, currentWorkNavController];
and I am setting the underRightViewController inside myWorkController
if (self.slidingViewController != nil)
{
UIViewController *underRightViewController = [[[UIViewController alloc] init] autorelease];
// configure under right view controller
underRightViewController.view.layer.borderWidth = 0;
underRightViewController.view.layer.backgroundColor = [UIColor colorWithWhite:0.9 alpha:1.0].CGColor;
underRightViewController.view.layer.borderColor = [UIColor colorWithWhite:0.8 alpha:1.0].CGColor;
underRightViewController.edgesForExtendedLayout = UIRectEdgeTop | UIRectEdgeBottom | UIRectEdgeRight; // don't go under the top view
self.slidingViewController.underRightViewController = underRightViewController;
}
1) First swipe works perfect but the second swipe breaks in ECSlidingViewController code
2) As I am using UINavigationController, when I try to change underRightViewController it fails at [oldUnderRightViewController removeFromParentViewController]; of ECSlidingViewController code
Can some one please guide me what I am doing wrong or if this is possible with ECSlidingViewController
Thanks in advance
I need to have a tabbar kind of view in a view controller(say view controller 3) which is in navigation stack and will be pushed by another view controller (say view controller 2).
I added tool bar to view controller 3 with many buttons. But managing and switching between views seems difficult.
How can i add a tabbar controller in the middle of navigation stack.
please help me out.
You cnt create tabbar in the middle of view controllers, you can create tab bar structure using custom segment controller. check the link below for creating custom segment controller.
https://www.cocoacontrols.com/search?q=segment
You cannot add TabBar there - tabBar is only designed to be at the bottom.
You have to create your own ViewController and add it as subView for navigationViewController and implement whole switching methods.
There has been some discussion about this design in related questions.
The way I understand your question it's definitely possible though. I am pushing a UITabBarController onto a UIViewController that is embedded in a UINavigationController. I did everything in the interfacebuilder except for the push which I implemented programmatically.
So in ViewController.m I added an action to a button:
- (IBAction)searchForPlacesButtonPressed:(id)sender {
TabBarController *tc = [[self storyboard] instantiateViewControllerWithIdentifier:#"TabBarController"];
tc.title = #"Orte";
tc.tabBar.selectedImageTintColor = [UIColor colorWithRed:(28.0f/255.0f) green:(100.0f/255.0f) blue:(52.0f/255.0f) alpha:1.0f];
UIBarButtonItem * logo = [[UIBarButtonItem alloc] initWithCustomView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"icon_xyz"]]];
tc.navigationItem.rightBarButtonItem = logo;
Places *d = [[Places alloc] init];
for (UIViewController *vc in tc.viewControllers) {
if ([vc isKindOfClass:[MapViewController class]]) {
((MapViewController *)vc).dataHandler = d;
((MapViewController *)vc).mapViewDelegate = d;
vc.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Karte" image:[UIImage imageNamed:#"map"] tag:0];
}
else if ([vc isKindOfClass:[TableViewController class]]) {
((TableViewController *)vc).dataHandler = d;
vc.tabBarItem = [[UITabBarItem alloc] initWithTitle:#"Liste" image:[UIImage imageNamed:#"eye"] tag:1];
}
}
[self.navigationController pushViewController:tc animated:YES];
}
Using the tabs at the bottom you can switch between viewing the places on a map and listed in a table.
I have a UITabBarController that is working good.
Now before I open the tabController, I want to check if the user is registered, if not I want to open a registration page (RegistrationController) and then go back to my tabView.
How can I do this, since the TabBarController can only be the first page.
Thank you
u can have a viewController(VC1) pushing another viewController (VC2) and in viewDidLoad of VC2 u can add ur tabbar programmatically.
tabBarController = [[UITabBarController alloc] init];
tabBarController.view.backgroundColor = [UIColor clearColor];
VC3 *object1 = [[VC3 alloc] initWithNibName:#"VC3" bundle:nil];
VC4 *object2 = [[VC4 alloc] initWithNibName:#"VC4" bundle:nil];
tabBarController.viewControllers = [NSArray arrayWithObjects:object1, object2, nil];
tabBarController.delegate = self;
[[tabBarController.viewControllers objectAtIndex:0] setTitle:#"title"];
[[tabBarController.viewControllers objectAtIndex:1] setTitle:#"title"];
[self.view addSubview:tabBarController.view];
[object1 release];
[object2 release];
also u can do this
in the viewDidLoad of the tabBarController (default view), u can check a variable, if its 0 (i.e. user is not registered), then u can presentModalViewController with a registration form.
hope it helps. happy coding :)
You can add an overlay, over the table view controller (another view which will make the table view not visible, since it will be behind the view you're adding). On succcessfull login / registration, you remove the overlay view.
I've had a good look at the Apple docs as well as similar Stack Overflow questions, but I am stuck on why my navigationController is null when using tab bars. I am trying to build most of the app from code, and am not using XIBs to insert a navigationController.
While debugging I have greatly simplified my app, down to two tabs. One tab holds a tableview and when a row is touched I'm expecting a detail page (from a XIB) to appear. Should be pretty simple. I am finding the value of self.navigationController is NULL when attempting to push the detail view, and of course it is then not working. I took the tab bar our completely and it works fine from a single view (the tableview). In this instance self.navigationController has a value.
AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// With Tab Bars
self.tabBarController = [[UITabBarController alloc] init];
ViewController *vc1 = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
vc1.tabBarItem.title = #"Words";
vc1.tabBarItem.image = [UIImage imageNamed:#"tab_feed.png"];
TextTableViewController *vc2 = [[TextTableViewController alloc] init];
vc2.tabBarItem.title = #"Text";
vc2.tabBarItem.image = [UIImage imageNamed:#"tab_live.png"];
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:vc1];
NSArray* controllers = [NSArray arrayWithObjects:vc2, navController, nil];
tabBarController.viewControllers = controllers;
tabBarController.delegate = self;
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
window.rootViewController = self.tabBarController;
[window makeKeyAndVisible];
return YES;
}
From TextTableViewController.m
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
TextViewController *detailViewController = [[TextViewController alloc] initWithNibName:#"TextViewController" bundle:nil];
Text *text = [[Text alloc] init];
text = [textArray objectAtIndex:indexPath.row];
detailViewController.TextID = text.textID;
NSLog(#"Nav Controller: %#",self.navigationController);
[self.navigationController pushViewController:detailViewController animated:YES];
NSLog(#"pushed");
}
I've also got two questions related to this problem.
(1) What is the purpose of this line. It doesn't appear to make a difference if it is in or out, and is absent from the Apple example.
tabBarController.delegate = self;
(2) When creating an array of tabs, one of the views is made the navigationController. Does it matter which tab it is or should this be a different view altogether not related to any tab and not visible. Is this where the problem lies?
In answer to question (1) about the tab bar controller's delegate, see the UITabBarControllerDelegate protocol reference. For the basic functionality of a tab bar controller, you don't need to bother with a delegate.
But let's say you want to do something special--for instance, save a document or reset an interface element to a default value--when the user changes tabs. You could make one of your classes, perhaps your app delegate or another controller class, conform to the UITabBarControllerDelegate protocol and implement tabBarController:didSelectViewController:
In your "answer" you asked if each tab will need its own UINavigation controller. That is absolutely correct. Basically, each tab is a completely independent hierarchy, so you need a separate UINavigation controller in each tab that requires one.
This should also imply the answer to your question (2) in the original post. You need to add the nav controller to the specific tab(s) that needs it.
OK I found it. The UINavigationController needs to be contained within the appropriate tab of the UITabBarController. So by making this coding change (below), a new UINavigationController is embedded in the tab with the tableview.
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:vc2];
NSArray* controllers = [NSArray arrayWithObjects:vc1, navController, nil];
Which then begs the question: what if you need multiple examples of this - do you create a new UINavigationController for each tab that has a need for one, and mark each one as a rootViewController?