gpt4 book ai didi

iphone - 无法更改 UITableView 的高度

转载 作者:行者123 更新时间:2023-12-03 18:28:22 25 4
gpt4 key购买 nike

在 Apple iPhone 时钟应用程序中,当用户添加新闹钟时,会弹出模态视图。我正在尝试创建一个与此类似的用户界面。

我目前有一个 UITableViewController 作为 UINavigationController 的 Root View Controller 。

我还添加了一个 UIDatePicker 作为 subview 到 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 的大小。我也想不通。

感谢您提供的任何帮助。

最佳答案

来自 UITableViewController class reference ,它:

creates an unconfigured UITableView object with the correct dimensions and autoresize mask

引用 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, only 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).

如果您不希望 TableView Controller 设置 tableView 的大小,那么您需要使用 UIViewController 来代替。请参阅我上面发布的 iOS TableView 编程指南的链接,了解采用此路线时需要考虑的其他事项。

关于iphone - 无法更改 UITableView 的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14794901/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com