drc
drc

Reputation: 1915

UITableView loads with cells in the middle of the TableView. Why?

Context

enter image description here

What I've tried

Result

Update

This is how the tableview looks on load. The green background shows all the white space that left on the top half of the bottom table view.

enter image description here

This is the code:

#pragma mark - Table View Methods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    if (tableView == self.topTableView) {
        return [self.array count];
    }
    else{
        return [self.array count];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableItem";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    if (tableView == self.topTableView) {
        cell.textLabel.text = @"60";

        return cell;
    }
    else{
        cell.textLabel.text = @"60";

        return cell;
    }

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}

Upvotes: 3

Views: 2655

Answers (1)

Helge Becker
Helge Becker

Reputation: 3243

Everything is fine with your code. It seems to be a bug with Xcode and iOS 7 unless I missed something in the WWDC documentation.

He applies the height of the navbar to the first element in the subviews array. It doesn't matter if the element is actually under the bar, he just blindly applies it. You can change the order in the storyboard, lets say you move the bottom tableview to the top, then the bottom view has the problem.

I see two options. If you disable "Under Top Bars" on the ViewController everything is fine. Or you move the UILabel to the top. There is nothing he can adjust with the static label. Maybe Xcode 5.0.1 that was released with the Maverics GM will fix that. Still downloading that one. Will try as soon DL is done.

enter image description here enter image description here

enter image description here

Upvotes: 2

Related Questions