views:

584

answers:

2

I am having some trouble with view hierarchies and drawing on the iPhone.

To be more specific, I have a tab bar application with a certain tab that contains a table view where I would like the selection of a specific cell to have a UIPickerView slide up. The sliding isn't really a problem (or at least I'm assuming it won't be once I figure this part out), but I cannot seem to get the picker (or any UIView, for that matter) to show up over the tab bar.

I think the way I have this certain tab set up may be the problem. Normally, in any other tab, I could just do something like this:

[self.tabBarController.view addSubview:pickerView];

and everything would work fine.

But for this specific tab, I have a UISegmentedControl in the navigation bar that switches between two different UITableViews. So the view controller associated with the tab (call it TabViewController) has its own instances of these two table view controllers (TableOneViewController and TableTwoViewController) and will insert the currently selected table view (based on the segmented control) as a subview of TabViewController's view.

If I didn't need to switch the views like this I could just call

[tabViewController.tabBarController.view addSubview:pickerView];

from TabViewController and the picker would show up over the tab bar. But the thing is I cannot call this in either of the table view controllers selected within this tab (well I can, but it doesn't do anything). I have tried passing this tabBarController property into the table view controller, but that doesn't work either. I have also tried messing around with the app delegate (which I'm trying to avoid) to no avail.

Is there something simple I'm missing here, or can this not be done? I feel like it should since a keyboard can slide up over the tab bar in this table view. Is there a way to just draw over all the current views and subviews?

Here is what is called when the segmented control is selected within TabViewController.m, and switches the views:

- (IBAction)switchViews:(id)sender
{
    if (self.tableOneViewController.view.superview == nil)
    {
        if (self.tableOneViewController == nil)
        {
            TableOneViewController *tempOneController = [[TableOneViewController alloc] initWithNibName:@"TableOneViewController" bundle:nil];
            self.tableOneViewController = tempOneController;
            [tempOneController release];
        }
        [tableTwoViewController.view removeFromSuperview];
        [self.view insertSubview:tableOneViewController.view atIndex:0];
    }
    else
    {
        if (self.tableTwoViewController == nil)
        {
            TableTwoViewController * tempOneController = [[TableTwoViewController alloc] initWithNibName:@"TableTwoViewController" bundle:nil];
            self.tableTwoViewController = tempOneController;
            [tempOneController release];
        }
        [tableOneViewController.view removeFromSuperview];
        [self.view insertSubview:tableTwoViewController.view atIndex:0];
    }
}

And here's what's going on when I try to add the picker in TableOneViewController.m:

UIPickerView *tempPicker = [[UIPickerView alloc] init];
tempPicker.delegate = self;
tempPicker.dataSource = self;
tempPicker.showsSelectionIndicator = YES;
tempPicker.clipsToBounds = NO; // thought this might work, but doesn't
self.picker = tempPicker;
[tempPicker release];
[self.view addSubview:pickerPicker]; // adds beneath tab bar!
+1  A: 

Maybe you want to do just

[tabBarController presentModalViewController:someViewController animated:YES];

?

This should slide on top of anything else you have on the screen.

Jaanus
I didn't read through the entire post... but Jaanus' answer is probably what you want
Ryan Ferretti
Thanks for the suggestions. This option did run through my mind, but I couldn't get it to work. Could have been any small thing I was doing wrong though...
presentModalViewController is a standard easy call, and the recommended way to show stuff on top of other stuff.
Jaanus
Just to follow up for any of those who may want to know... while researching my modal view controller problem I came across another thread that stated that the modal view controllers are only transparent in animation, and become opaque once in place. This was the problem with using this for me personally, since I want the view underneath to be seen as well.
"the modal view controllers are only transparent in animation, and become opaque once in place" sounds bogus. View controllers can't be anything, it's their "enclosed" views that are transparent or not. You configure view transparency in code or Interface Builder.
Jaanus
A: 
[[[UIApplication sharedApplication] keyWindow] addSubview:someViewController];

Make sure the viewController you are loading in is 480px high!

To remove it again, use [someViewController removeFromSuperview];

Emil
This is what I was looking for. Thank you for the suggestion. I know my post was verbose to say the least. Figures that the solution is incredibly simple!
You could also add a simple animation to it, too, so that it doesen't just appear :)
Emil