【问题标题】:ios first cell is not start from top of UITableViewios第一个单元格不是从UITableView的顶部开始
【发布时间】:2016-11-09 12:19:17
【问题描述】:

我的应用程序有一个导航和 UITableView。我将 backgroundColor 设置为我的 tableView。看下面的图片。我不明白为什么第一个单元格不是从 UITableView 顶部开始的。 我在Xcode中使用View Debbuger时,UITableView中TableViewWrapperView没有填满。

我已经搜索过很多次了。我删除了检查Adjust Scroll View Insets 并设置.zero tableview 的contentinsets。最后我制作了新项目并再次制作,但我做不到。

我该如何解决这个问题!!

enter image description here

【问题讨论】:

标签: ios swift uitableview


【解决方案1】:

此问题的简单解决方案

无需为此问题编写代码。只需按照以下简单步骤即可

YourStoryboard.storyboard > YourViewController > 属性检查器 > 取消选中 - 调整滚动视图插图。

这里我附上截图供参考。

如果你喜欢使用代码,我也有解决方案:)

- (void)viewDidLoad {
      self.automaticallyAdjustsScrollViewInsets = false
}

【讨论】:

    【解决方案2】:

    这是给像我这样尝试了上述所有方法但可能错过了这一点的灵魂。我不小心将 tableview 样式用作 Grouped 而不是 Plain。

    因此,在 xib/storyboard 或代码中将您的 Tableview 样式设置为“Plain”而不是“Grouped”

    目标 C

    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    

    斯威夫特 4,0

    self.tableView = UITableView(frame: CGRect.zero, style: .plain)
    

    【讨论】:

    • 我在重构后遇到了这个问题,我忘记了我在进程中更改了tableview样式。经过两个小时检查差异、调试和谷歌搜索后,我终于找到了你的答案。我需要的单词样式触发器。 Thnx 由于和thanx SO ?
    • 我能感觉到疼痛兄弟 :-)
    【解决方案3】:

    假设导航栏是半透明的并且它必须在它后面显示自己,表格视图会尝试调整自身以适应导航栏。

    要在 storyboard/xib 文件中解决这个问题,将视图控制器属性将顶栏下的边延伸设置为 false,如下所示。

    【讨论】:

    • 当我取消选择“顶部栏下”时,导航栏的背景会改变颜色。知道如何使其与选中时保持一致吗?
    • @spijs 这可能是因为您的导航栏的背景颜色可能有 alpha。您可能希望背景使用纯色以保持一致性。
    【解决方案4】:

    发现它适用于 iOS 11 及更高版本,使用:

        self.tableView.contentInsetAdjustmentBehavior = .never
    

    【讨论】:

      【解决方案5】:

      打开故事板,点击UITableView。在您的sizeInspector 中,将部分高度字段中的HeaderFooter 设置为1。

      【讨论】:

        【解决方案6】:

        打开您的故事板并单击包含表视图的表视图控制器/视图控制器。打开属性检查器并取消勾选Adjust Scroll View Insets

        【讨论】:

          【解决方案7】:

          我回答我自己的问题。

          我不知道top layout guideview 有什么不同。 但我决定将顶部约束 0 设置为 view

          谢谢。

          enter image description here

          【讨论】:

            【解决方案8】:

            在您的视图控制器的 viewdidload 上写下这两行,它将解决您的问题

            self.edgesForExtendedLayout = UIRectEdgeNone;
            self.automaticallyAdjustsScrollViewInsets = NO;
            

            【讨论】:

              【解决方案9】:

              iOS 11 后的解决方案

              tableView.contentInsetAdjustmentBehavior = .never
              

              【讨论】:

                【解决方案10】:

                我尝试了下面的代码,但没有成功。

                self.edgesForExtendedLayout = UIRectEdgeNone;  
                _tableView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;  
                _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
                

                我的解决方案:

                - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
                    return 1.0;
                }
                
                - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
                    UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0.0,
                                                                              0.0,
                                                                              self.tableView.frame.size.width,
                                                                              1.0)];
                    header.backgroundColor = [UIColor whiteColor];
                    
                    return header;
                }
                

                【讨论】:

                  猜你喜欢
                  • 2015-05-01
                  • 1970-01-01
                  • 2014-01-17
                  • 1970-01-01
                  • 1970-01-01
                  • 2014-05-08
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多