iphone - 调整表格 View 大小

标签 iphone uitableview resize

我正在寻找一种方法,让 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 实现 UITableViewDelegateUITableViewDataSource 协议(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/

相关文章:

iphone - 使用 GKMatch 的 Game Center Multiplayer 但似乎无法连接

iphone - 如何制作一个应用程序的两个版本并让它们共享相同的设置?

ios - 当应用程序从内存中卸载时(iphone,内存不足)本地通知到达时会发生什么

ios - UItabelView 不显示我的内容

iOS Swift - 带有左侧细节和右侧细节和副标题的 UITableViewCell?

c++ - vector resize() 自动填充

iOS 应用程序在后台显示通知,但不在前台 iPhone 4s 和操作系统版本 9.3

ios - 如何强制自定义单元格的 UIImageView 覆盖表格分隔符?

ruby - 使用 Rmagick 和 Carrierwave 调整 gif 文件大小而不失真

javascript - 单击单选按钮时动态调整 iFrame 大小