我有一个 10 行的 UITableView。通过单击第一行,我想滚动到 UITableView 的第 5 行。
我怎样才能做到这一点?
应该管用!
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row == 0) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:4 inSection:0];
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
}
试试这个:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
{
if (indexPath.row == 0) {
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:5 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
}