【问题标题】:uitableviewcell get offset after set navigationBarHidden = YES and and a custom bar viewuitableviewcell 在设置 navigationBarHidden = YES 和自定义栏视图后获得偏移量
【发布时间】:2016-10-25 09:24:16
【问题描述】:

THE BUG PICTURE

这张图是bug图片,我的代码如下:

- (void)viewDidLoad
{
[super viewDidLoad];

self.navigationController.navigationBarHidden = YES;
naviview = [[UIImageView alloc] init];
naviview.backgroundColor = [UIColor colorWithHexString:@"fcfcfc"];
naviview.frame = CGRectMake(0, 0, VIEW_BOUNDS.width, 64);
[self.view addSubview:naviview];

self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, VIEW_BOUNDS.width, self.view.bounds.size.height-62-TABBARHEIGHT) style:UITableViewStylePlain];

self.tableView.showsHorizontalScrollIndicator = NO;
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.backgroundColor = [UIColor grayColor];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view insertSubview:_tableView belowSubview:self.naviview];

}

如果我使用[self.view insertSubview:_tableView belowSubview:self.naviview];,则单元格有一个偏移量,如果我使用[self.view addSubview:_tableView],则单元格将是正确的。我想知道导致偏移的原因,有人可以告诉我吗?

非常感谢!

【问题讨论】:

  • 以编程方式使用自动布局约束添加表格视图,使用顶部布局指南添加表格顶部约束
  • 您是否设置了任何节标题?
  • 尝试禁用调整滚动视图 insest self.automaticallyAdjustsScrollViewInsets = NO;
  • @Joshua 没有节标题
  • @GevorgGhukasyan 这不起作用,我试过了。

标签: ios objective-c uitableview uinavigationbar


【解决方案1】:

因为当您使用addSubview 时,它会被添加到superview 上,并且tableview 的和框架将使用视图的框架来计算。但是在insertSubView 中被添加到navView 后面。可能 tableView 框架正在使用不同的框架进行计算。

您可以通过将tableView框架高度设置为0来验证它,然后尝试使用insertSubView

【讨论】:

  • 框架仍然是 self.view 它实际上并没有改变。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-22
  • 1970-01-01
  • 1970-01-01
  • 2015-01-12
相关资源
最近更新 更多