我想在完成表演后滚动到UITableView的底部 [self.tableView reloadData]
我原本有
[self.tableView reloadData]
NSIndexPath* indexPath = [NSIndexPath indexPathForRow: ([self.tableView numberOfRowsInSection:([self.tableView numberOfSections]-1)]-1) inSection: ([self.tableView numberOfSections]-1)];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
Run Code Online (Sandbox Code Playgroud)
但后来我读了reloadData是异步的,所以滚动不因为发生self.tableView,[self.tableView numberOfSections]并且[self.tableView numberOfRowsinSection都是0.
谢谢!
有什么奇怪的是我正在使用:
[self.tableView reloadData];
NSLog(@"Number of Sections %d", [self.tableView numberOfSections]);
NSLog(@"Number of Rows %d", [self.tableView numberOfRowsInSection:([self.tableView numberOfSections]-1)]-1);
Run Code Online (Sandbox Code Playgroud)
在控制台中它返回Sections = 1,Row = -1;
当我完成相同的NSLogs时,cellForRowAtIndexPath我得到Sections = 1和Row = 8; (8是对的)
我有一个UITableView与cells被动态地更新.一切正常,除了tableview.reload调用时(见下文)刷新cells表中我希望表滚动到底部以显示新条目.
- (void)reloadTable:(NSNotification *)notification {
NSLog(@"RELOAD TABLE ...");
[customTableView reloadData];
// Scroll to bottom of UITable here ....
}
Run Code Online (Sandbox Code Playgroud)
我打算使用scrollToRowAtIndexPath:atScrollPosition:animated:但后来注意到我无法访问indexPath.
有谁知道怎么做,或者delegate我可以使用的回调?
在Apple的消息应用程序中,当您单击通讯员的名称并切换到对话的表格视图(每个消息都有气球)时,表格会一直滚动到最后.没有动画或任何东西,它就在那里.
同样,在Tweetie 2中,当您加载推文视图时,它会显示在您上次查看它的位置.没有动画到达那里,它就在那里,好像上面没有任何单元格被加载.
这些应用程序如何做到这一点?他们scrollToRowAtIndexPath:atScrollPosition:animated:在桌面控制器的某个地方打电话吗?如果是这样,他们怎么知道要传递给atScrollPosition:谁?它叫什么方法?