在viewDidLoad之后,我尝试以编程方式将框架大小设置为表视图:
[_tableView setFrame:CGRectMake(0, topHeight,
[[UIScreen mainScreen] bounds].size.width,
[[UIScreen mainScreen] bounds].size.height - topHeight)];默认大小为200x200,原点为Y 100:

场景层次:

UITableView的实现显示了调用setFrame时的情况:
@implementation MainTableView
- (void)setFrame:(CGRect)frame {
NSLog(@"setFrame: %f %f", frame.size.width, frame.size.height);
[super setFrame:frame];
}
@end一切都很好,但是当我按下任何单元格而不打印来自setFrame的日志消息时,表的帧会调整为默认的。小解说视频:rHvCS2I
我不明白为什么在单元格单击后,我的表大小变成默认(200x200)。即使我试图在viewWillAppear中设置大小(从单元格详细信息视图返回后),它也不起作用。
有什么想法吗?
发布于 2015-07-31 17:31:01
我不知道为什么您的tableView没有正确地调整大小,因为您没有提供太多的代码来查看。虽然我建议为tableView设置一些约束或调整大小的规则,但可能如下所示:
http://i.imgur.com/N9fvvIB.png (如果不使用自动布局)
http://i.imgur.com/3Uz8e5e.png (如果使用自动布局)
现在,如果您真的需要使这个工作只通过代码,我建议抛出一些NSLog,其中包含表视图的帧宽度和高度,在设置之前和之后。
发布于 2015-07-31 22:15:13
试试_tableView.translatesAutoresizingMaskIntoConstraints = NO。
https://stackoverflow.com/questions/31750908
复制相似问题