3
votes

Context

  • Building for iOS 7
  • Two UITableViews on a viewcontroller
  • Using constraints so tableview resize like I'd like for between 3.5inch and 4inch screen sizes.

enter image description here

What I've tried

  • Read UITableView documentation
  • Search stackoverflow
  • tried this code: [self.bottomTableView scrollToRowAtIndexPath:0 atScrollPosition:UITableViewScrollPositionTop animated:NO];

Result

  • The content in the bottom tableView loads in the middle of the tableview. I can scroll those cells upwards towards the top of the table view, but they "snap" back to the middle. How do I avoid this?

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 {

}
1
can you show actual images with cell & also your tableview code?Jay Gajjar
Please, can you show the code where you ser up the tableView (frame, delegates...)? Thank you?RFG
I dont see problems with the code you provide, but I dont see how you set up the tableview in code or interfacebuilder. Nor can I see whats happen during runtime. Mind zipping the project and share it, so we can look closer?Helge Becker
@HelgeBecker here you go: dl.dropboxusercontent.com/u/529504/Example.zipdrc

1 Answers

2
votes

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 hereenter image description here

enter image description here