简体   繁体   中英

Can't scroll UITableView to bottom

EDIT
This is what happens, so you can see: http://youtu.be/v1HrxYhzJZY .

This is my scenario:
I have a UITableView with 5 sections and 12 cells. This view is opened with a push segue and everything works fine, it scrolls, etc.

Three of those cells open a MKMapView view (through a push segue ) another pops up a MFMailComposeViewController .

When I try to go back to my UITableView I'm no longer able to scroll to the bottom. I can only scroll a bit and then it returns to the top of my tableview.

I tried to set the frame size on viewWillAppear , I tried to reload the tableView but it doesn't work!
What could cause this issue?

EDIT
My implementation are:

- (void)viewDidLoad {
    loaded = NO;

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"my_url", self.userID]];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        loaded = YES;

        self.user = JSON;
        [self setUserValues];

        [self.tableView reloadData];

    } failure:nil];

    [operation start];

    [super viewDidLoad];
}

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

    [self.tableView setContentSize:CGSizeMake(320, 420)];
}

I solved that issue by myself with this simple code:

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

    [self.tableView reloadData];
}

Thanks anyway!

The viewWillAppear: method is too early to scroll the table view. The view hasn't been added to the on-screen view hierarchy and laid out yet. Try doing it in viewDidLayoutSubviews .

使用以下代码将tableView滚动到所需的部分/行:

[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:desiredRow inSection:desiredSection] atScrollPosition:UITableViewScrollPositionTop animated:NO];

To scroll the tableView, which inherits from UIScrollView , you need to use [self.tableView setContentOffset:CGPointMake(0,100) animated:YES]; and not the setContentSize

I experienced this too. Coming back from the child view, the table view was no longer scrollable (it would always bounce to the top). My child view doesn't have a map view like yours.

Reloading the table view didn't fix it for me.

The bug only showed in iOS 7, not 6.1.

I was accessing topLayoutGuide ... removing that access (just a property read!) fixed the issue. WTF! Must be a magic property.

I also met this problem yesterday! And I have fixed it just now!

I dragged a UITableView to the UIViewController and simply chose add missing contraints . When I ran the app, the UITableView could not scroll to bottom.

I googled it and saw a similar question in Stackoverflow .

Then I checked the contraints for the UITableView, I found there was a contraint setted the fixed height for the UITableView. Then I removed the contraint and added another one: Bottom Space to: Bottom Layout Guide = 0 .

The solution works for me.

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