【发布时间】:2010-02-12 04:08:56
【问题描述】:
我在 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!
【问题讨论】:
标签: iphone objective-c cocoa-touch iphone-sdk-3.0