Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)];
}
like image 712
jacoz Avatar asked Dec 23 '12 15:12

jacoz


4 Answers

I solved that issue by myself with this simple code:

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

    [self.tableView reloadData];
}

Thanks anyway!

like image 151
jacoz Avatar answered Sep 18 '22 23:09

jacoz


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.

like image 31
rob mayoff Avatar answered Sep 17 '22 23:09

rob mayoff


Use the following code to scroll your tableView to desired section/row:

[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:desiredRow inSection:desiredSection] atScrollPosition:UITableViewScrollPositionTop animated:NO];
like image 41
Misha Avatar answered Sep 16 '22 23:09

Misha


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

like image 42
Lefteris Avatar answered Sep 16 '22 23:09

Lefteris