简体   繁体   中英

UITableView Won't Scroll

I've got a UITableViewController in my storyboard and for some strange reason, I can't get it to scroll. Please see this video to see what I mean:

UITableView Won't Scroll

The table has like 40 rows in it, so there is plenty of info for it to display. It sort of behaves like the frame is just really really tall so that it's able to show all of the rows and the only movement from dragging is the stretch and bounce.

I added some code in -viewDidAppear: to check the frame , bounds , contentSize and insets :

- (void) viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    UIEdgeInsets insets = self.tableView.contentInset;
    NSLog(@"top layout guide: %f", self.topLayoutGuide.length);
    NSLog(@"table insets: %@", NSStringFromUIEdgeInsets(insets));

    NSLog(@"frame: %@", NSStringFromCGRect(self.tableView.frame));
    NSLog(@"bounds: %@", NSStringFromCGRect(self.tableView.bounds));
    NSLog(@"contentSize: %@", NSStringFromCGSize(self.tableView.contentSize));

}

This is what it printed out:

top layout guide: 64.000000
table insets: {64, 0, 0, 0}
frame: {{0, 0}, {320, 568}}
bounds: {{0, -64}, {320, 568}}
contentSize: {320, 1980}

So, the contentSize shows that is has plenty to show and the frame/bounds shows that the table is only as tall as the screen, so why the heck isn't this able to scroll?

I tried deleting it from my storyboard and recreating it from scratch just in case something got tweaked and was causing the problem, but it still happens after I rebuilt that view controller in the storyboard.

EDIT:

I noticed that the scrollbars flash when the view controller is first shown, and they look approximately the right length to represent one screen's worth of the table data. I set up a loop that calls -flashScrollIndicators on the table every few seconds it doesn't even show a scroll bar after the initial flashing when the view controller is pushed onto the stack.

I have NO idea why this causes a problem, perhaps someone can help me understand.

I went through the normal isolation tactics of commenting out large sections of code until the problem disappeared and then narrowing down until I found the issue. It all came down to this line of code:

NSLog(@"top layout guide: %f", self.topLayoutGuide.length);

With that line of code, the table refuses to scroll.

Without that line of code, the table behaves normally.

Project zip file which demonstrates the problem:

http://www.inadaydevelopment.com/stackoverflow/TableScrollBug.zip

I face same problem after spending so much time i found the AutoLayout is enable and when it is disabled, it start scrolling

so, did AutoLayout is disabled?

I think your problem is with AutoLayout. If you are using AutoLayout then you should also provide some constraints to resize it properly according to it's superview. I think you have to provide width constraint on your TableView. and other constraint like vertical distance from TopLayoutGuide and BottomLayoutGuide. If you are using Xcode 5.0 or newer then Xcode will give you warnings regarding missing constraints or Conflicting constraints. Refer this if you are not aware of Constraints. One another good tutorial for AutoLayout Constraints this .

You could try to add missing constraints automatically. In Xcode use Editor -> Resolve Auto Layouts Issues -> Add Missing Constraints.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM