Scott
Scott

Reputation: 1222

Table view frame showing up at unintended location

This is what my view controller looks like with these two table views. As you can see, the left looks like the frame is in the intended place and the right does not. I've posted my code and the origin y is in the same place in both. What could be causing this?

View Controller Image with two table views

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    CGFloat halfLength = self.view.frame.size.width / 2;
    CGRect ingredientsFrame = CGRectMake(0, 0, halfLength - 1, self.view.frame.size.height);
    CGRect modsFrame = CGRectMake(halfLength + 1, 0, halfLength - 1, self.view.frame.size.height);

    _ingredientsTableView = [[UITableView alloc] initWithFrame:ingredientsFrame style:UITableViewStyleGrouped];
    _ingredientsTableView.delegate = self;
    _ingredientsTableView.dataSource = self;
    _ingredientsTableView.tag = 1;
    [self.view addSubview:_ingredientsTableView];
    _modsTableView = [[UITableView alloc] initWithFrame:modsFrame style:UITableViewStyleGrouped];
    _modsTableView.delegate = self;
    _modsTableView.dataSource = self;
    _modsTableView.tag = 2;
    [self.view addSubview:_modsTableView];
}

Upvotes: 0

Views: 58

Answers (1)

matt
matt

Reputation: 534925

You need to set the second table view's contentInset and scrollIndicatorInsets to compensate for the fact that the top of the table view is up underneath the navigation bar.

The reason you don't see the same problem in the first table view is that this done for you automatically for the first scroll view in your interface.

Upvotes: 1

Related Questions