lundi 18 juillet 2016

Start table view at top after app becomes active

I want my table view to scroll to the top after my app becomes active, but I want to do this before the view actually displays. Is this possible?

Here is my code so far:

- (void)viewDidLoad{

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];

}

- (void)applicationDidBecomeActive{

[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];

}

This works, however you can see the table view jumping to the top, so it is actually executed after the view has appeared. Using viewDidAppear would work, but that method is not called when the app is becoming active from the background.

Any ideas?

Thanks!

Aucun commentaire:

Enregistrer un commentaire