IPhone view hierarchy question: how do I draw views on the tab bar?

I'm having problems with view hierarchies on the iPhone too.

To be more specific, I have a tab bar application with a specific tab that contains a table view where I would like the selection of a specific cell to have a UIPickerView slide. Sliding is not really a problem (or at least I suppose it won't be as soon as I figure it out), but I can't force the collector (or any UIView, for that matter) the tab bar.

I think the problem is that I have this specific tab set. Usually on any other tab, I could just do something like this:

[self.tabBarController.view addSubview:pickerView];

and everything will work fine.

But for this particular tab, I have a UISegmentedControl in the navigation bar that switches between two different UITableViews. Thus, the view controller associated with the tab (call 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 subtask of the TabViewController view.

If I didn’t need to switch to such views, I would just call

[tabViewController.tabBarController.view addSubview:pickerView];

TabViewController, . , (, , ). tabBarController , . ( ) .

- , , ? , , . ?

, TabViewController.m :

- (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];
    }
}

, 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!
+3
2
[[[UIApplication sharedApplication] keyWindow] addSubview:someViewController];

, viewController 480 !

, [someViewController removeFromSuperview];

+7

,

[tabBarController presentModalViewController:someViewController animated:YES];

?

, .

+2

Source: https://habr.com/ru/post/1732463/


All Articles