Unable To Add Second Tab Bar to Tab Controller - ios5

I have two tab bars in order to have effect like the one shown in Question of Sliding UITabBarItems in UITabBarController
Instead of an arrow, I am trying to use tab bar item at last index to show another tab bar, and hiding the current tab bar. I am adding second tab bar programmatically in viewDidLoad. Problem is that my second tab bar is not showing up on when last tab bar item is tapped. What I have done is:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.tabControler.view.frame = self.view.frame;
self.tabControler.delegate = self;
self.secondTabBarSelected = NO;
self.secondTabBar = [[UITabBar alloc] initWithFrame:CGRectMake(0, 431, 320, 49)];
self.secondTabBar.hidden = YES;
self.secondTabBar.delegate = self;
self.secondTabBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[self.tabControler.view addSubview:secondTabBar];
[self.view addSubview:tabControler.view];
NSLog(#"children of tabcon: %#",[tabControler.view subviews]); //Here second tab bar added with correct frame
}
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
if (!self.secondTabBarSelected) {
NSLog(#"first tab bar");
if([[tabBarController viewControllers] indexOfObject:viewController] == 3)
{
self.firstTabBar.hidden = YES;
self.secondTabBar.hidden = NO;
}
}
}

I found that my tab bar was not visible because I was allocating it explicitly while it was present in nib file. Instead I just set the frame. My corrected code is:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.tabControler.view.frame = self.view.frame;
self.tabControler.delegate = self;
self.secondTabBarSelected = NO;
self.secondTabBar.frame = self.firstTabBar.frame;
self.secondTabBar.hidden = YES;
self.secondTabBar.delegate = self;
NSLog(#"viewdidload frame: %#",secondTabBar.frame);
self.secondTabBar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[self.tabControler.view addSubview:self.secondTabBar];
NSLog(#"viewdidload frame: %#",secondTabBar.frame);
[self.view addSubview:tabControler.view];
}
-(void) tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
NSLog(#"first tab bar - controller");
if([[tabBarController viewControllers] indexOfObject:viewController] == 3)
{
self.firstTabBar.hidden = YES;
self.secondTabBar.hidden = NO;
self.secondTabBarSelected = YES;
}
}

Related

Bring Tab bar back after using navigation bar

I have an app that based on Tab Bar combined with navigation bar.
In the navigation bar i have a button that takes me to another page which I want to hide the tab bar. When i trying to back to the main view through a button (Not back bar button, regular one) i can't bring the Tab Bar back.
I did try : xxxxx.hidesBottomBarWhenPushed =NO;
Here is some of my code:
In main view:
In viewDidLoad:
UIBarButtonItem *flipButton = [[UIBarButtonItem alloc]
initWithTitle:buttonTitle
style:UIBarButtonItemStylePlain
target:self
action:#selector(goToCreateEvent)];
-(void)goToCreateEvent{
UIViewController *targetViewController;
NSString *viewControllerName = #"CreateAnEventViewController";
targetViewController = [[NSClassFromString(viewControllerName) alloc] initWithNibName:viewControllerName bundle:nil];
targetViewController.hidesBottomBarWhenPushed =YES; //Hides the tab bar
[self.navigationController pushViewController:targetViewController animated:YES];
}
In the other view:
-(IBAction)save:(id)sender
{
[summary resignFirstResponder];
[agenda resignFirstResponder];
FeedViewController *aboutViewCont = [[FeedViewController alloc] init];
aboutViewCont.hidesBottomBarWhenPushed =NO; //trying to bring back the tab bar
[[self navigationController] pushViewController:aboutViewCont animated:NO];
}
Thanks!
Yossi
This simply solve it:
[[self navigationController] popToRootViewControllerAnimated:YES];
in viewWillAppear: method of FeedViewController set hidesBottomBarWhenPushed to NO like bellow..
-(void)viewWillAppear:(BOOL)animated{
self.hidesBottomBarWhenPushed = NO;
}
UPDATE: Try out this one also..
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
CGRect r = self.tabBarController.view.frame;
r.size.height +=self.tabBarController.tabbar.frame.size.height;
self.tabBarController.view.frame = r;
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
self.tabBarController.view.frame = CGRectMake(0, 0, 320, 480); //for iPhone portrait
}
use this above methods in your FeedViewController class and also just comment this bellow line from your code..
targetViewController.hidesBottomBarWhenPushed =YES;//comment this..

ViewController with subviews, UIScrollView not scrollable first time

Im using a UIViewController with several subviews from XIBs, (ViewController's views), they are chosen between using UISegmentedControl. One of these views are containing a UIScrollView. The problem is that the UIScrollView is not scrollable the first time this subview is added. If I choose another segment/view and then the one with the UIScrollView again, now it's scrollable.
The UIScrollView is added in IB only. This is some of the codes for the views and UISegmentedControl in MainViewController.m
- (void)viewDidLoad
{
[super viewDidLoad];
nameSubViewController = [[NameSubViewController alloc] initWithNibName:#"NameSubViewController" bundle:nil];
nameSubView = (NameSubView *)[nameSubViewController view];
priceSubViewController = [[PriceSubViewController alloc] initWithNibName:#"PriceSubViewController" bundle:nil];
priceSubView = (PriceSubView *)[priceSubViewController view];
[self.view addSubview:nameSubView];
currentView = nameSubView;
}
- (void) segmentAction:(id)sender
{
segmentedControl = sender;
if([segmentedControl selectedSegmentIndex] == 0) {
[currentView removeFromSuperview];
[self.view addSubview:nameSubView];
currentView = nil;
currentView = nameSubView;
}
if([segmentedControl selectedSegmentIndex] == 1) {
[currentView removeFromSuperview];
[self.view addSubview:priceSubView];
currentView = nil;
currentView = priceSubView;
}
In this code, let's say segment 1 (priceSubView) contains the UIScrollView. If I choose this segment, the UIScrollView does not react on the scrolling unless I choose segment 0 (nameSubView) again and re-select segment 1.
What is causing this and how to fix it?
If you need to scroll at first load.
You need to add the scrollView at firstLoad.
You are adding the scroll view after changing the segment control, that's why it's not scrolling. Check it out.
Change viewDidLoad like:
- (void)viewDidLoad
{
[super viewDidLoad];
nameSubViewController = [[NameSubViewController alloc] initWithNibName:#"NameSubViewController" bundle:nil];
nameSubView = (NameSubView *)[nameSubViewController view];
priceSubViewController = [[PriceSubViewController alloc] initWithNibName:#"PriceSubViewController" bundle:nil];
priceSubView = (PriceSubView *)[priceSubViewController view];
[self.view addSubview:priceSubView];
currentView = priceSubView;
}

add two navigation controller to one Tab bar Item

I want 2 navigation Controller to be attached to one Tab bar item.
Basically the idea is to have 2 views on a single tab Item and there should be a navigation bar to push and pop the screens. (same like settings application in iPad).
edited======
It will look like on left hand side there is a View with its own navigation Controller and on right hand side there is another View with its own navigation controller(or some other UI) to achieve the Push Pop stuff.
I know how to attach 1 navigation Controller to one Tab bar Item.
Edited For ModalView Issue:-
by implementing conmulligan code everything works property. But if I try to display some ModalViewController in lansdscape mode and when I try to close this ModalView the FirstViewController navigationbar becomes portrait(along with its View) and SecondViewController NavigationBar remains landscape(at it should be). This happens only in Device not in simulator.
Below is my Code of presenting the ModalViewController.
ModalTableViewController *modalTableViewController = [[ModalTableViewController alloc]initWithNibName:#"ModalTableViewController" bundle:[NSBundle mainBundle]];
UINavigationController *localNavigationViewController = [[UINavigationController alloc] initWithRootViewController:modalTableViewController];
localNavigationViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:localNavigationViewController animated:YES];
[modalTableViewController release];
[localNavigationViewController release];
For Dismising the ModalViewCntroller I do it as below:-
[self dismissModalViewControllerAnimated:YES];
Waiting for your replies.
One way would be to create a UIViewController subclass that contains two navigation controllers and add that to the UITabBarController. Here's how you'd create and layout the navigation controllers in the UIViewController's -viewDidLoad method:
FirstViewController *firstViewController = [[FirstViewController alloc] init];
UINavigationController *firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
[firstViewController release];
SecondViewController *secondViewController = [[SecondViewController alloc] init];
UINavigationController *secondNavigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
[secondViewController release];
firstNavigationController.view.frame = CGRectMake(0.f, 0.f, 320.f, self.view.frame.size.height);
firstNavigationController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight;
secondNavigationController.view.frame = CGRectMake(321.f, 0.f, self.view.frame.size.width - 321.f, self.view.frame.size.height);
secondNavigationController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth |
UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:firstNavigationController.view];
[self.view addSubview:secondNavigationController.view];
This is more or less how the UISplitViewController works under the hood.
Edit: you might need to add the following code to make sure it lays out properly:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[firstNavigationController viewWillAppear:animated];
[secondNavigationController viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[firstNavigationController viewWillDisappear:animated];
[secondNavigationController viewWillDisappear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[firstNavigationController viewDidAppear:animated];
[secondNavigationController viewDidAppear:animated];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[firstNavigationController viewDidDisappear:animated];
[secondNavigationController viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}

bringSubviewToFront not showing it's view

In my table view controller, I have a button that when I press, I want it to show the map view, so I just did the following. However, for some reason it's not showing up the view... why is this>
- (void)viewDidLoad {
mapViewController = mapViewController = [[MapViewController alloc] init];
[super viewDidLoad];
}
-(IBAction) toggleAction:(id) sender {
[self.view bringSubviewToFront:mapViewController.view];
self.navigationItem.backBarButtonItem = nil;
}
You need to add the view as a subview:
-(IBAction) toggleAction:(id) sender {
[self.view addSubView:mapViewController.view];
self.navigationItem.backBarButtonItem = nil;
}
Then remove it on dismissal (removeFromSuperView).

Cannot create a view with a UIScrollView

I am looking for some help for a program I am developing. Basically, it contains two views. The first view has a button and a action related to it leads me to my next view where there is a scroll view for three pages ( as in the PageControl sample given by apple.) I am using navigation controller to push the view from the first view to the second view. But on pushing I am not able to scroll the page or using page control or anything. It just comes a normal view. The code is same as pageControl code and it works fine as a separate module. But when I want to integrate this pageControl code with a first view and a click button it doesn't work. Please help.
//this function is an action set against a button in the rootviewcontroller.
-(IBAction) viewScrollPages:(id)sender{
UIViewController *controller = [[MyViewController alloc] initWithPageNumber:0];
[self.navigationController pushViewController:controller animated:NO];
[controller release];
}
- (id)initWithPageNumber:(int)page {
if (self = [super initWithNibName:#"MyViewController" bundle:nil]) {
pageNumber = page;
}
return self;
}
- (void)viewDidLoad {
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (unsigned i = 0; i < kNumberOfPages; i++) {
[controllers addObject:[NSNull null]];
}
self.viewControllers = controllers;
[controllers release];
// a page is the width of the scroll view
scrollView.pagingEnabled = YES;
scrollView.contentSize = CGSizeMake(scrollView.frame.size.width * kNumberOfPages, scrollView.frame.size.height);
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.scrollsToTop = NO;
scrollView.delegate = self;
pageControl.numberOfPages = kNumberOfPages;
pageControl.currentPage = 0;
// pages are created on demand
// load the visible page
// load the page on either side to avoid flashes when the user starts scrolling
[self loadScrollViewWithPage:0];
[self loadScrollViewWithPage:1];
pageNumberLabel.text = [NSString stringWithFormat:#"Page %d", pageNumber + 1];
self.view.backgroundColor = [MyViewController pageControlColorWithIndex:pageNumber];
[super viewDidLoad];
}
It sounds like your pushing a normal view that is a subview of the scrollview instead of pushing the scrollview itself.