我有一个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];
}
}
在此链接How to scroll UITableView to specific position中检查答案
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:YourIndex inSection:0];
[YourTableView scrollToRowAtIndexPath:indexPath
atScrollPosition: UITableViewScrollPositionMiddle
animated:YES];