Reputation: 3516
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)];
}
Upvotes: 5
Views: 9295
Reputation: 1346
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.
Upvotes: 0
Reputation: 23398
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.
Upvotes: 1
Reputation: 3516
I solved that issue by myself with this simple code:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.tableView reloadData];
}
Thanks anyway!
Upvotes: 7
Reputation: 14687
To scroll the tableView, which inherits from UIScrollView
, you need to use [self.tableView setContentOffset:CGPointMake(0,100) animated:YES];
and not the setContentSize
Upvotes: 1
Reputation: 385998
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
.
Upvotes: 5
Reputation: 5380
Use the following code to scroll your tableView to desired section/row:
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:desiredRow inSection:desiredSection] atScrollPosition:UITableViewScrollPositionTop animated:NO];
Upvotes: 1