我在查看层次结构和在iPhone上绘图时遇到了一些麻烦。iPhone视图层次结构问题:如何在标签栏上绘制视图?
更具体地说,我有一个标签栏应用程序,其中包含一个表格视图,我希望选择一个特定的单元格以使UIPickerView向上滑动。滑动不是一个真正的问题(或者至少我假设它不会是一次我认为这一部分了),但我似乎无法让选择器(或任何UIView,就此而言)显示过来标签栏。
我认为我设置这个特定标签的方式可能是问题所在。通常情况下,在任何其他标签中,我可以这样做:
[self.tabBarController.view addSubview:pickerView];
和一切都会正常工作。
但是对于这个特定的选项卡,我在导航栏中有一个UISegmentedControl,它在两个不同的UITableView之间切换。因此,与该选项卡相关的视图控制器(称为TabViewController)具有其自己的这两个表视图控制器(TableOneViewController和TableTwoViewController)的实例,并将当前选定的表视图(基于分段控件)作为TabViewController视图的子视图。
如果我没有需要切换这样的意见,我可以打电话
[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!
这就是我正在寻找的。感谢您的建议。我知道我的帖子是冗长的,至少可以说。数字表明解决方案非常简单! – Kevin 2010-02-13 03:22:30
你也可以添加一个简单的动画,以便它不会出现:) – Emil 2010-02-13 12:31:44