UITableview滚动到特定索引,该单元格作为第一个索引位于顶部吗?

问题描述 投票:1回答:1

我有一个array包含过去和将来事件的数据。当页面加载时,tableview滚动到以后的第一个事件。向下滚动时间显示过去的事件

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    NSInteger index = 0;
    if ([arryIndex count]!=0) {
        NSNumber * indexPathData = [arryIndex objectAtIndex:index];
        int number = [indexPathData intValue];
        [tableEvents setContentOffset:CGPointMake(0.0, tableEvents.contentSize.height - tableEvents.bounds.size.height)animated:YES];
        [tableEvents scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:number inSection:0]atScrollPosition:UITableViewScrollPositionTop animated:YES];
    }
}
objective-c uitableview uiscrollview ios11
1个回答
0
投票

在此链接How to scroll UITableView to specific position中检查答案

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:YourIndex inSection:0];
[YourTableView scrollToRowAtIndexPath:indexPath 
                 atScrollPosition: UITableViewScrollPositionMiddle 
                         animated:YES];
© www.soinside.com 2019 - 2024. All rights reserved.