更改视图大小后,TableView消失了。

3

以下是代码:

self.dataTableViewController = [[DataTableViewController alloc] initWithStyle:UITableViewStylePlain];
CGRect tableViewRect = self.dataTableViewController.view.frame;
tableViewRect.origin.x = 0.0f;
tableViewRect.origin.y = 91.0f;
//tableViewRect.size.width = 320.0f;
//tableViewRect.size.height = 613.0f;
self.dataTableViewController.view.frame = tableViewRect;
[self.view addSubview:self.dataTableViewController.view];

我的tableviewcontroller显示出来了,一切正常,也放置在正确的位置上。但是我的表格大小不正确。如果我取消注释掉我的两行代码来设置大小属性,表格视图就会从我的uiview中消失,而我不知道为什么。

有什么想法吗?

//编辑:

好吧,有些奇怪的行为。我的视图控制器,其中我的tableview被显示,在一个splittableviewcontroller(左侧)中。

self.contentSizeForViewInPopover = CGSizeMake(320.0, 704.0); 对我的popovercontroller没有任何影响。我将其保留为默认值,来自splittableviewcontroller模板。如果我处于纵向模式下,它总是全高。

取消注释tableViewRect.size.height = 613.0f;可以工作,取消注释宽度则不行。将我的高度设置为613px,我得到一个高度为313px的表格视图。什么!?将我的高度设置为913.0f后,在横屏和竖屏模式下都完美。我不明白的是,在横屏模式下应该只有613px高。我想将我的popover的高度设置为与我的视图控制器在横屏模式下相同的高度,以便我的表格视图始终为613高。没有任何想法发生了什么。

我的913像素的tableview:

landscape

portrait


您能否发布您的源代码下载链接?如果可以的话,那会更好。 - Daniel Amitay
抱歉,我无法翻译。该项目正在进行中,而且我已经完成了很多额外的工作。没有这种简单结构的样例。 - choise
2个回答

1

You are trying to insert the table view as subview of another view. Then you try to specify a frame. What may happen is that even if you specify the frame, your table is still a subview of another view and then it will be subject to any autoresizing rule you may have initially set. So have you checked that setting the frame explicitly is not conflicting with the table autoresizing mask? in particular, you can try by setting for the table autoresizing mask the value

UIViewAutoresizingNone
(do this in the viewDidLoad method is recommended).


0

对我来说有效...你的代码是在表视图控制器中还是其他类中?我尝试了这个(它有效):

CGRect tableViewRect = self.tableView.frame;

tableViewRect.origin.x = 0.0f;
tableViewRect.origin.y = 91.0f;
tableViewRect.size.width = 320.0f;
tableViewRect.size.height = 613.0f;

self.tableView.frame = tableViewRect;

[self.tableView setNeedsLayout];
[self.tableView setNeedsDisplay];

顺便说一下,我认为iPhone的尺寸是320 x 480,所以我不确定你为什么在那里使用613。


这是一个针对 iPad 的代码。此代码位于视图控制器(self)内部。DataTableViewController 是表视图控制器。你为什么要调用 setNeedsLayoutsetNeedsDisplay - choise
因为每次调整大小或进行UIView动画时,都需要刷新布局和显示。是这样吗?如果代码是针对iPad的,它也应该能够正常工作。现在它是否正常工作? - Enrico Susatyo
现在无法检查,可能需要大约9个小时。 - choise
嗨Choise,我现在明白你想做什么了,但是我在这里真的帮不上太多忙...我以前从未使用过popovercontroller。 - Enrico Susatyo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接