Note that there are some explanatory texts on larger screens.

plurals
  1. POscrollToRowAtIndexPath scrolls to the second last row instead of the last row
    primarykey
    data
    text
    <p>I have a messagesTableView which is shown in a ViewController in a NavigationController.</p> <p>In viewDidLoad:</p> <pre><code>[self.messagesTableView reloadData]; NSInteger t; if ((t = [self.messagesTableView numberOfRowsInSection:0]) &gt; 0) { NSLog(@"ViewDidLoad: number of rows:%d Messages Count:%d", t, [messages count]); NSIndexPath* ip = [NSIndexPath indexPathForRow: (t-1) inSection:0]; [self.messagesTableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionNone animated:NO]; } </code></pre> <p><img src="https://i.stack.imgur.com/WkyYJ.png" alt="As you can see, the last row is partially shown"></p> <p>and in viewDidAppear:</p> <pre><code>[self.messagesTableView reloadData]; NSInteger t; if ((t = [self.messagesTableView numberOfRowsInSection:0]) &gt; 0) { NSLog(@"ViewDidAppear: number of rows:%d Messages Count:%d", t, [messages count]); NSIndexPath* ip = [NSIndexPath indexPathForRow: (t - 1) inSection:0]; [self.messagesTableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionTop animated:NO]; } </code></pre> <p><img src="https://i.stack.imgur.com/TpfGo.png" alt="The last is shown completely"></p> <p>The scrollToRowAtIndexPath in viewDidLoad scrolls to second last row instead of the last row whereas the same function in viewDidAppear scrolls to the last row.. The only problem is that it takes a while for the viewDidAppear function to be called..</p> <p>but why does it behave differently in viewDidLoad and viewDidAppear (the NSLog is printing the same values for both)?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload