【问题标题】:UITableViewController last Row cut offUITableViewController 的最后一行被截断
【发布时间】:2011-10-06 18:39:13
【问题描述】:

我遇到了一个问题,在我的 UITableViewController 中,最后一行总是被截断一半。

如果我有 20 行,第 20 行将被截断;如果我有 30 个,第 30 个将被切断。

我尝试调整 contentSize 的大小和 UITableViewController 的框架,但它不起作用。

有没有办法将 UITableViewController 调整为正确的大小?

提前致谢。

一些代码:

在另一个类中初始化它:

 settingsTable = [[SettingTableViewController alloc] init];
    settingsTable.view.frame = CGRectMake(0, 0, 320, 480);
    [self.view addSubview:settingsTable.view];

在 UITableViewController 中:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return [settingsData count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [[settingsData objectForKey:[NSString stringWithFormat:@"%d", section]] objectAtIndex:0];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[[settingsData objectForKey:[NSString stringWithFormat:@"%d", section]] objectAtIndex:1] intValue];
}

我没有在 UITableViewController 的任何地方调整框架的大小

【问题讨论】:

  • 您可能一开始就将 UITableView 的框架设置错了。提供一些代码会有所帮助:)
  • 您说您尝试调整 ViewController 的大小,但您是否仍然使用 Interface Builder 来放置视图,如果是这样,是否留下了最终的 NavigationBars 或 TabBars?
  • @Phlibbo 虽然它不是从 .xib 文件中加载的..

标签: iphone objective-c ios uitableview


【解决方案1】:

在界面构建器中,选择UITableView,然后在“视图”选项下移除底部的自动调整大小栏。如果它们与下面的屏幕截图不同,您可以保留所有其他内容。重要的是底部竖条。

改变这个:

到这里:

或者,以编程方式进行:

settingsTable.autoresizingMask &= ~UIViewAutoresizingFlexibleBottomMargin;

编辑来自 cmets):

您的状态栏设置为显示还是隐藏?如果它正在显示,则将框架线更改为:

settingsTable.view.frame = CGRectMake(0, 0, 320, 460);

或者,尝试其中一种,看看它们是否有帮助:

settingsTable.view.frame = self.view.bounds;
// or
settingsTable.view.frame = self.view.frame;

【讨论】:

  • 我更改了 settingsTable.autoresizingMask &= ~UIViewAutoresizingFlexibleBottomMargin;,然后最后一行完全消失了 0-0...当我将其更改为“UIViewAutoresizingFlexibleHeight”时,最后一行被削减了大约 1 /5 ..
  • 或者,您可以这样做:settingsTable.view.frame = self.view.bounds;settingsTable.view.frame = self.view.frame;
【解决方案2】:

在容器控制器中使用 UITableViewController 并设置半透明 UI 栏时), 所以我认为正确处理它的 contentInset 是“应用程序的一面”。

你可以试试

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 44, 0);

【讨论】:

    【解决方案3】:

    问题出在这一行:

    settingsTable.view.frame = CGRectMake(0, 0, 320, 480);
    

    您没有考虑状态栏的高度(纵向 20 像素)。总可用高度实际上是 460px 而不是 480px。这就是为什么你在底部损失了 20px。您应该根据父视图边界计算布局子视图的帧,而不是硬编码它们:

    settingsTable.view.frame = self.view.bounds;
    

    【讨论】:

      【解决方案4】:

      您可以使用以下代码

      //检查设备方向 - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 持续时间:(NSTimeInterval)持续时间 { if (([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft) || ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight)) { NSLog(@"风景"); //设置tableview的高度(tableview的高度-Navbar的高度) self.messageTableView.contentInset = UIEdgeInsetsMake(0, 0, self.view.frame.size.height-64, 0); } 别的 { NSLog(@"人像"); self.messageTableView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0); } }

      【讨论】:

        【解决方案5】:

        我在iOS 8遇到了类似的问题

        只需在我的tableView 中调整部分页脚高度即可解决问题。

        【讨论】:

          【解决方案6】:

          使用自动布局时,请确保 tableView 的底部约束相对于它的容器设置为 0。

          通过代码设置(PureLayout)

          [tableView autoPinEdge:ALEdgeBottom toEdge:ALEdgeBottom ofView:containerView withOffset:0];
          

          【讨论】:

            【解决方案7】:

            可能是你的限制,我只是遇到了这个问题,直到我发现我的 tableview 被限制为 superview 的高度和宽度,但意外地居中在切断底部的安全区域 x 和 y 中..

            【讨论】:

            • 我在查看这篇文章时留下了这个答案,试图在 2018 年解决同样的问题,这就是我遇到这个问题的原因。我认为把它留在这里是有效的,因为它可能会帮助像我一样在这个时候搜索问题的人,我当然不欣赏否决票!
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2019-11-11
            • 1970-01-01
            • 2013-04-12
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多