【问题标题】:UITableView too wide for portrait iPadUITableView 对于纵向 iPad 来说太宽了
【发布时间】:2017-04-12 23:36:34
【问题描述】:

这几天让我发疯了......

  • 为 iPad 创建一个新的基于窗口的应用程序。
  • 使用 XIB 创建一个针对 iPad 的新 UITableViewController 类。
  • 将 UITableViewController 视图作为子视图添加到 AppDelegate 窗口。
  • 在笔尖中将表格样式设置为分组。
  • 在 iPad 模拟器中运行,表格单元格离开屏幕的右端

如果我允许旋转并重新加载 tableView,那么它随后会正确调整大小。在 iPhone 上运行 sim 显示正常,只是 iPad 纵向初始视图大小错误。

【问题讨论】:

    标签: ipad uitableview


    【解决方案1】:

    我在窗口的子视图中遇到了类似的 UITableView 问题。我通过在 viewDidLoad 中设置 UINavigationController 的框架大小来解决它。由于某种原因,子视图没有将自身限制在 Interface Builder 中指定的视图大小。这对我有用:

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        UINavigationController *navigationController = [[UINavigationController alloc] init];
        RootViewController *rootController = [[[RootViewController alloc] initWithStyle:UITableViewStylePlain] autorelease];
        rootController.managedObjectContext = self.managedObjectContext;
        [navigationController.navigationBar setBarStyle:UIBarStyleBlackOpaque];
        [navigationController pushViewController:rootController animated:YES];
        [navigationController.view setFrame:CGRectMake(0, 0, 500, self.view.frame.size.height)];
        [self.leftView addSubview:[navigationController view]];
    }
    

    【讨论】:

      【解决方案2】:

      确保 UITableViewController 的原点 x&y 为 0,0,并查看 UITableViewController 的 autosizing 属性

      【讨论】:

      • 原点是 0,0。对不起,我不明白你所说的查看 autosizing 属性是什么意思。但是,我的理解是,当视图作为子视图添加时,它会自动调整大小以适合包含的视图。但是,当我执行 [self.window addSubview:theiPadTableViewController.view] 然后 NSLog 窗口边界宽度和视图边界宽度时,我分别得到 768 和 1216。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      • 2013-03-07
      • 1970-01-01
      • 2021-06-07
      • 1970-01-01
      • 2019-07-29
      • 2020-08-08
      相关资源
      最近更新 更多