如何将 UITableViewWrapper 的大小调整为与 UITableView 相同的大小?

Posted

技术标签:

【中文标题】如何将 UITableViewWrapper 的大小调整为与 UITableView 相同的大小?【英文标题】:How to adjust size of UITableViewWrapper to same size as UITableView? 【发布时间】:2016-03-23 13:03:17 【问题描述】:

我的问题是 TableView 顶部的空白:

一开始我以为是标题:

但没有修复,我什至在代码中修改了这些:

最后我看到这是调试中的包装视图:

我不想像这样循环遍历子视图,即使它没有解决我的问题:

for (UIView *subview in tableView.subviews)

    if ([NSStringFromClass([subview class]) isEqualToString:@"UITableViewWrapperView"])
    
        subview.frame = CGRectMake(0, 0, tableView.bounds.size.width, tableView.bounds.size.height);
    

任何人都知道为什么会发生这种情况,因为我以前没有遇到过这样的问题!

【问题讨论】:

我什至尝试在 heightForHeaderInSection 中返回浮点值但没有成功! 这个解决方案对我有用:***.com/questions/27671324/… 【参考方案1】:

我解决了这个问题

-(void)viewWillLayoutSubviews
  [super viewWillLayoutSubviews];
  self.tableView.contentInset = UIEdgeInsetsZero;
  self.tableView.scrollIndicatorInsets = UIEdgeInsetsZero;
  

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection: (NSInteger)section
  return 0.01;
   

【讨论】:

【参考方案2】:

对我来说,这是通过禁用 Extend Edges: Under Top Bar in Storyboard 来解决的。

Extend Edges screenshot

或以编程方式:

viewController.edgesForExtendedLayout = []

这将禁止扩展到任何边缘。

【讨论】:

以上是关于如何将 UITableViewWrapper 的大小调整为与 UITableView 相同的大小?的主要内容,如果未能解决你的问题,请参考以下文章