iPhone视图层次结构问题:如何在标签栏上绘制视图?

Kev*_*vin 3 iphone cocoa-touch objective-c iphone-sdk-3.0

我在查看层次结构和在iPhone上绘图时遇到了一些麻烦.

更具体地说,我有一个标签栏应用程序,其中包含一个包含表格视图的选项卡,我希望选择特定单元格以使UIPickerView向上滑动.滑动不是一个真正的问题(或者至少我假设它不会一次我把这个部分弄清楚),但我似乎无法让选择器(或任何UIView,就此而言)出现标签栏.

我认为我设置这个标签的方式可能就是问题所在.通常,在任何其他选项卡中,我可以执行以下操作:

[self.tabBarController.view addSubview:pickerView];
Run Code Online (Sandbox Code Playgroud)

一切都会好起来的.

但是对于这个特定的选项卡,我在导航栏中有一个UISegmentedControl,可以在两个不同的UITableView之间切换.因此,与选项卡关联的视图控制器(称为TabViewController)具有这两个表视图控制器(TableOneViewController和TableTwoViewController)的自己的实例,并将插入当前选定的表视图(基于分段控件)作为TabViewController视图的子视图.

如果我不需要像这样切换视图,我可以打电话

[tabViewController.tabBarController.view addSubview:pickerView];
Run Code Online (Sandbox Code Playgroud)

从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];
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试在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!
Run Code Online (Sandbox Code Playgroud)

Emi*_*mil 7

[[[UIApplication sharedApplication] keyWindow] addSubview:someViewController];
Run Code Online (Sandbox Code Playgroud)

确保你加载的viewController是480px高!

要再次删除它,请使用 [someViewController removeFromSuperview];