开发者

iPhone view hierarchy question: How do I draw views over the tab bar?

I am having some trouble with view hierarchies and drawing on th开发者_如何转开发e 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!


[[[UIApplication sharedApplication] keyWindow] addSubview:someViewController];

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

To remove it again, use [someViewController removeFromSuperview];


Maybe you want to do just

[tabBarController presentModalViewController:someViewController animated:YES];

?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜