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
.
Use the following code to scroll your tableView to desired section/row:
[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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With