在 Apple iPhone 时钟应用程序中,当用户添加新闹钟时,会弹出一个模式视图。我正在尝试创建一个类似的 UI。
我目前有一个 UITableViewController 作为 UINavigationController 的根视图控制器。
我还添加了一个 UIDatePicker 作为 UINavigationController 的子视图:
[self.navigationController.view addSubview:mydatePicker];
但是,我的 UITableview(UITableViewController 的)中有大约 10 多行,一旦添加了 UIDatePicker,我就无法滚动查看所有单元格。
我意识到 UITableView 的大小与添加 UIDatePicker 之前的大小相同,因此我需要更改它的大小才能滚动查看所有表格单元格。
我尝试了几件事来改变它的大小,但都无济于事。在下面的代码中,我任意选择了 50 作为新高度。
首先,尝试更改边界高度:
CGRect bounds = [self.tableView bounds];
[self.tableView setBounds:CGRectMake(bounds.origin.x,
bounds.origin.y,
bounds.size.width,
50)];
然后尝试改变框架高度:
CGRect tvframe = [self.tableView frame];
[self.tableView setFrame:CGRectMake(tvframe.origin.x,
tvframe.origin.y,
tvframe.size.width,
50)];
然后在谷歌搜索了一些之后,我尝试更改 contentSize 高度:
CGSize thesize = self.tableView.contentSize;
thesize.height = 50;
self.tableView.contentSize = thesize;
这些似乎都对 UITableView 的大小没有任何影响。我仍然无法滚动查看所有单元格。
后来我尝试了一些与上面相同的方法,但在 UINavigationController 而不是 UITableView 上。我也没有太多运气。
作为最后的手段,我尝试在 Storyboard 编辑器中更改 UITableView 的大小。我也想不通。
感谢您的任何帮助,您可以提供。