1

我有一个 UITableViewController,我需要垂直调整表格的大小。

我不能使用带有表的 UIViewController

有方法吗?

谢谢!

4

2 回答 2

5

这只有在您的UITableViewController视图被手动添加到另一个超级视图时才有可能。但是,如果您计划在导航控制器中使用表格视图或作为模式表,您无法控制表格视图的大小。

要完全控制表视图大小:

  1. UIViewController使用UITableView插座和资源文件让您拥有自己的子类。
  2. 在其内容之上放置一个 UITableViewview并相应地调整它的大小。
  3. 使您的视图控制器实现UITableViewDataSourceUITableViewDelegate协议。
  4. 连接插座。
于 2012-11-05T03:17:48.900 回答
2

而不是使用 a ,使用带有属性UITableViewController的标准可能更容易。UIViewControllerUITableView

例如:

@interface ContentsPopover : UIViewController <UITableViewDelegate, UITableViewDataSource>
//...
@property (nonatomic, strong) UITableView *theTableView;
//...
@end

这样,UIViewController您可以在您的内部拥有以下代码(可能在 viewDidLoad 中):

theTableView = [[UITableView alloc] initWithFrame:/*...*/ style:UITableViewStylePlain];

theTableView.delegate = self;
theTableView.dataSource = self;
theTableView.scrollEnabled = YES;

[self.view addSubview:theTableView];

// You can now change theTableView's frame property as needed

当 aUITableViewController不是您要查找的内容时,这很方便。

于 2012-11-05T03:13:35.607 回答