【发布时间】:2016-10-25 09:24:16
【问题描述】:
这张图是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