Search code examples
iphoneuitableviewios7quickdialog

UITableView not scrolling after switching to iOS 7


In iOS 6, I had a UITableView created using QuickDialog in my app. It scrolled normally. When I switched to iOS 7, the same UITableView does not scroll properly. I can drag to the bottom (the scroller compresses) but when I release, it pops back up the to the top. I've been playing with viewDidAppear to try and diagnose the problem. See the code block below.

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    NSLog(@"Content height: %f",self.quickDialogTableView.contentSize.height);
    [self.quickDialogTableView reloadData];
    NSLog(@"Content height: %f",self.quickDialogTableView.contentSize.height);
    [self.quickDialogTableView layoutIfNeeded];
    NSLog(@"Content height: %f",self.quickDialogTableView.contentSize.height); 
 }

The output of this block in iOS 7 is

Content height: 0.000000
Content height: 836.000000
Content height: 0.000000

Meanwhile, the output of this block in iOS 6 (simulator) is

Content height: 836.000000
Content height: 836.000000
Content height: 836.000000

Also to try and diagnose the problem, I set up a button that would trigger [self.quickDialogTableView reloadData]. Whenever that button is pushed, the scrolling behavior begins to function normally. Then when I leave the view and come back, the scrolling fails again (until the button is pushed). To be clear, I have tried to put a reloadData in viewWillAppear by itself (i.e., removing the last two lines in the code block above) and it does not correct the scrolling.

I'm looking for clues as to where I might look to correct the issue. Thanks in advance for any help.


Solution

  • Okay, so I couldn't figure out the source of the problem but I did find a workaround that I hope helps someone else. Or at least, maybe helps someone else point out what's really wrong.

    I created a property called trueContentSize where I store what the correct size is.

    -(void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
        [self.quickDialogTableView reloadData]; // Calculates correct contentSize
        self.trueContentSize = self.quickDialogTableView.contentSize; 
    }
    

    Then, in -viewDidLayoutSubviews I correct the contentSize manually.

    -(void)viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
        self.quickDialogTableView.contentSize = self.trueContentSize; 
    }