在iOS7之前,我们通过UITableViewIndexSearch
在章节索引标题之前添加一个放大镜图标到UITableView索引顶部。
通过拖动到部分索引中的放大镜图标,tableView可以使用以下代码滚动到searchBar:
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
NSInteger resultIndex = [self getSectionForSectionIndex:index];
// if magnifying glass
if (resultIndex == NSNotFound) {
[tableView setContentOffset:CGPointZero animated:NO];
return NSNotFound;
}
else {
return resultIndex;
}
}
但是,在iOS 7中,这只会滚动到第一部分,而不是搜索栏。
为了解决这个问题,我们调整了内容偏移量以解决iOS 7中引入的UITableView的内容插图: CGPointMake(0.0, -tableView.contentInset.top)
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
NSInteger resultIndex = [self getSectionForSectionIndex:index];
// if magnifying glass
if (resultIndex == NSNotFound) {
[tableView setContentOffset:CGPointMake(0.0, -tableView.contentInset.top)];
return NSNotFound;
}
else {
return resultIndex;
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句