iOS 7表格视图横向单元格宽度

iOS 7表格视图横向单元格宽度,ios,uitableview,uiviewcontroller,Ios,Uitableview,Uiviewcontroller,我已将表视图添加到UI视图控制器。当我将手机旋转到横向模式时,手机的宽度并没有完全填满整个视图。请参见下面的屏幕截图 在这里似乎找不到优雅的解决方案 编辑:您可以在此处下载我的不调整大小的横向视图示例: 使用自动布局或使用适当的自动调整大小遮罩添加UITableView 以编程方式 自动布局: UITableView *tableView = [[UITableView alloc] init]; tableview.translatesAutoresizingMaskIntoConstrai

我已将表视图添加到UI视图控制器。当我将手机旋转到横向模式时,手机的宽度并没有完全填满整个视图。请参见下面的屏幕截图

在这里似乎找不到优雅的解决方案

编辑:您可以在此处下载我的不调整大小的横向视图示例:


使用自动布局或使用适当的自动调整大小遮罩添加UITableView

以编程方式

自动布局:

UITableView *tableView = [[UITableView alloc] init];
tableview.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:tableView];
NSDictionary *viewsDictionary = @{@"tableView" : tableView };

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[tableView]|"
                                                                      options:kNilOptions
                                                                      metrics:nil
                                                                        views:viewsDictionary]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[tableView]|"
                                                                      options:kNilOptions
                                                                      metrics:nil
                                                                        views:viewsDictionary]];
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:tableView];
自动调整掩码大小:

UITableView *tableView = [[UITableView alloc] init];
tableview.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:tableView];
NSDictionary *viewsDictionary = @{@"tableView" : tableView };

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[tableView]|"
                                                                      options:kNilOptions
                                                                      metrics:nil
                                                                        views:viewsDictionary]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[tableView]|"
                                                                      options:kNilOptions
                                                                      metrics:nil
                                                                        views:viewsDictionary]];
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:tableView];
界面生成器/情节提要

自动布局:

UITableView *tableView = [[UITableView alloc] init];
tableview.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:tableView];
NSDictionary *viewsDictionary = @{@"tableView" : tableView };

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[tableView]|"
                                                                      options:kNilOptions
                                                                      metrics:nil
                                                                        views:viewsDictionary]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[tableView]|"
                                                                      options:kNilOptions
                                                                      metrics:nil
                                                                        views:viewsDictionary]];
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:tableView];
控制从表格视图到superview的拖动,并添加以下约束:

自动调整遮罩大小(无自动布局):

UITableView *tableView = [[UITableView alloc] init];
tableview.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:tableView];
NSDictionary *viewsDictionary = @{@"tableView" : tableView };

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[tableView]|"
                                                                      options:kNilOptions
                                                                      metrics:nil
                                                                        views:viewsDictionary]];
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[tableView]|"
                                                                      options:kNilOptions
                                                                      metrics:nil
                                                                        views:viewsDictionary]];
UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:tableView];
如果使用手动帧操作,则这些应该是表视图的自动调整大小掩码

注意

说真的,老兄,我已经给了你尽可能多的空间,让你的观点更灵活。如果你很难理解这一点,那么我建议你回去看看一些开始iOS开发的教程。是启动iOS时所能想到的一切的神奇资源

更新

添加了约束的测试项目。我花了大约5秒钟的时间。看看iPhone的故事板


看起来apple iOS 7方向调整表视图存在一些问题

在正确的位置使用以下命令可以解决问题

[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows]
withRowAnimation:UITableViewRowAnimationNone];

除了此调用之外,如果需要,还必须根据
cellforRowIndexPath
数据源中的新方向大小更改宽度

但我并不是通过编程将表视图添加到视图控制器中。我把它拖到了风景区。我从来没有像你所说明的那样真正“更新”过表视图。这同样适用吗?无限詹姆斯很抱歉让这个挂起-我今晚要试试这个,马克接受了,如果是这样:)我仍然不确定如何让这个工作。您是否能够提供一个简单的示例xcode项目,该项目显示一个表视图,该表视图位于常规视图上,在横向模式下会增长?有趣的是,如果我把一个导航控制器放在那里,它附带的表视图就可以做到这一点,但我无法复制。infity james:我上传了一个非常简单的示例项目,来说明我的问题:回答一个问题没有什么意义,只是希望得到分数。我很高兴我真的能帮你,伙计,这就是我为什么费心的原因。