使用子视图添加tableView,tableView的footerView无法显示。
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, KNavgationBarHeight + kStatusBarHeight, self.view.frame.size.width, 200)];
view.backgroundColor = [UIColor redColor];
view.userInteractionEnabled = YES;
[self.view addSubview:view];
self.btn = [UIButton buttonWithType:UIButtonTypeCustom];
self.btn.frame = CGRectMake(0, 0, 200, 30);
[self.btn setTitle:@"跳" forState:UIControlStateNormal];
self.btn.center = view.center;
[self.btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.btn];
DetailViewController *detailVC = [[DetailViewController alloc] init];
[self.view addSubview:detailVC.view];
[self addChildViewController:detailVC];
[detailVC didMoveToParentViewController:self];
[detailVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(@0);
}];
DetailViewController viewDidLoad:
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 200 + KNavgationBarHeight + kStatusBarHeight, self.view.frame.size.width, self.view.frame.size.height)];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 135)];
footerView.backgroundColor = [UIColor whiteColor];
[footerView addSubview:self.checkBtn];
self.checkBtn.center = footerView.center;
self.tableView.tableFooterView = footerView;
[self.tableView registerClass:[XHAccountStep4CreditAuthCell class] forCellReuseIdentifier:@"cell"];
原因是子控制器中tableView高度没有减去导航栏高度KNavgationBarHeight + kStatusBarHeight和上面的红色视图的高度200。tableView的frame高度不能写死。要么减去KNavgationBarHeight + kStatusBarHeight + 200,要么添加约束到vc的view的四边。
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 200 + KNavgationBarHeight + kStatusBarHeight, self.view.frame.size.width, self.view.frame.size.height - 200 - KNavgationBarHeight - kStatusBarHeight)];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 135)];
footerView.backgroundColor = [UIColor whiteColor];
[footerView addSubview:self.checkBtn];
self.checkBtn.center = footerView.center;
self.tableView.tableFooterView = footerView;
[self.tableView registerClass:[XHAccountStep4CreditAuthCell class] forCellReuseIdentifier:@"cell"];
或
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 200 + KNavgationBarHeight + kStatusBarHeight, self.view.frame.size.width, self.view.frame.size.height)];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.view addSubview:self.tableView];
UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 135)];
footerView.backgroundColor = [UIColor whiteColor];
[footerView addSubview:self.checkBtn];
self.checkBtn.center = footerView.center;
self.tableView.tableFooterView = footerView;
[self.tableView registerClass:[XHAccountStep4CreditAuthCell class] forCellReuseIdentifier:@"cell"];
[self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(264);
make.left.equalTo(@0);
make.right.equalTo(@0);
make.bottom.equalTo(@0);
}];