Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在重新加载数据后转到UITableView中的第一个单元格_Ios_Objective C_Uitableview - Fatal编程技术网

Ios 如何在重新加载数据后转到UITableView中的第一个单元格

Ios 如何在重新加载数据后转到UITableView中的第一个单元格,ios,objective-c,uitableview,Ios,Objective C,Uitableview,当前,当我重新加载表中的数据时,它将保持在相同的滚动位置: [self.tableView reloadData]; 如何获取滚动位置/高度以返回顶部/第一个单元格?您可以使用以下方法滚动到表视图中的任何索引路径: [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES]; 因此,对于第一个单元格,您的indepath将是: NSIn

当前,当我重新加载表中的数据时,它将保持在相同的滚动位置:

[self.tableView reloadData];

如何获取滚动位置/高度以返回顶部/第一个单元格?

您可以使用以下方法滚动到表视图中的任何索引路径:

[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
因此,对于第一个单元格,您的
indepath
将是:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

您可以更改
滚动位置
动画
参数以获得所需的效果/结果。

您可以使用以下方法滚动到表视图中的任何索引路径:

[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
因此,对于第一个单元格,您的
indepath
将是:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];

您可以更改
滚动位置
动画
参数以获得所需的效果/结果。

Swift 4版本

let indexPath = IndexPath(row: 0, section: 0)
tableView.scrollToRow(at: indexPath, at: .top, animated: false)

Swift 4版本

let indexPath = IndexPath(row: 0, section: 0)
tableView.scrollToRow(at: indexPath, at: .top, animated: false)

我发生此崩溃是因为我试图滚动到空tableView的第0行第0节。在执行scrollToRow()之前,请确保tableData.count>0。

我遇到此崩溃,因为我试图滚动到空tableView的第0行第0节。在执行scrollToRow()之前,请确保tableData.count>0。

这将是
[self.tableView ScrollToRowatinedExath:0 atScrollPosition:UITableViewScrollPositionTop动画:是]?对不起。我删除了评论,因为我在错误的地方声明了:)非常感谢你的回答,真是太棒了!那就是
[self.tableView scrollToRowatinexpath:0atScrollPosition:UITableViewScrollPositionTop动画:是]?对不起。我删除了评论,因为我在错误的地方声明了:)非常感谢你的回答,真是太棒了!