我正在寻找一种方法,让 UITableViewController 的顶部有一个 UITableView,下面有一个 UIPickerView(具有固定位置)。
我找到了使用以下代码修复选择器的解决方案:
- (void)viewDidLoad {
[super viewDidLoad];
_picker = [[UIPickerView alloc] initWithFrame:CGRectZero];
_picker.showsSelectionIndicator = YES;
_picker.dataSource = self;
_picker.delegate = self;
// Add the picker to the superview so that it will be fixed
[self.navigationController.view addSubview:_picker];
CGRect pickerFrame = _picker.frame;
pickerFrame.origin.y = self.tableView.frame.size.height - 29 - pickerFrame.size.height;
_picker.frame = pickerFrame;
CGRect tableViewFrame = self.tableView.frame;
tableViewFrame.size.height = 215;
self.tableView.frame = tableViewFrame;
[_picker release];
}
问题出在表格 View 上,调整大小似乎不起作用,所以我看不到所有结果。
感谢您的建议。
最佳答案
如果要管理的 View 由多个 subview 组成,其中一个是 TableView ,则应使用 UIViewController
子类而不是 UITableViewController
来管理 TableView 。您可以添加 UITableView
subview ,并使 Controller 实现 UITableViewDelegate
和 UITableViewDataSource
协议(protocol)。
UITableViewController
类的默认行为是使表格 View 填充导航栏和选项卡栏(如果存在)之间的屏幕。
来自Table View Programming Guide for iOS :
Note: You should use a UIViewController subclass rather than a subclass of UITableViewController to manage a table view if the view to be managed is composed of multiple subviews, one of which is a table view. The default behavior of the UITableViewController class is to make the table view fill the screen between the navigation bar and the tab bar (if either are present).
If you decide to use a UIViewController subclass rather than a subclass of UITableViewController to manage a table view, you should perform a couple of the tasks mentioned above to conform to the human-interface guidelines. To clear any selection in the table view before it’s displayed, implement the viewWillAppear: method to clear the selected row (if any) by calling deselectRowAtIndexPath:animated:. After the table view has been displayed, you should flash the scroll view’s scroll indicators by sending a flashScrollIndicators message to the table view; you can do this in an override of the viewDidAppear: method of UIViewController.
关于iphone - 调整表格 View 大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6432088/