我想UITableView
通过点击sectionIndexTitles
侧面的来滚动浏览我的内容UITableView
。到目前为止,我的解决方案如下:
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
NSIndexPath *matchingIndexPathForTitle = [self matchingIndexPathForSectionIndexTitle:title];
if (matchingIndexPathForTitle) {
[tableView scrollToRowAtIndexPath:matchingIndexPathForTitle
atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
return 1;
}
但自iOS9以来,它似乎始终滚动到顶部UITableView
我可以保证matchingIndexPathForTitle
正确(例如,第1节,第22行),并且更改为animated:NO
不会造成任何影响。
你
由于sectionForSectionIndexTitle
负责滚动到右侧部分而不是单元格,因此在此方法中返回有效的部分索引号将取消所有自定义滚动事件。
为了滚动到单元格,必须防止滚动到该部分。这可以通过返回无效的段索引(例如-1)来完成
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
NSIndexPath *matchingIndexPathForTitle = [self matchingIndexPathForSectionIndexTitle:title];
if (matchingIndexPathForTitle) {
[tableView scrollToRowAtIndexPath:matchingIndexPathForTitle
atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
return -1; // this will do the trick and not scroll to any section
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句