在iOS7之前,我们在UITableView索引的顶部添加了一个放大镜图标,方法是在节索引标题前加上UITableViewIndexSearch。
通过拖动到节索引中的放大镜图标,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中,这只会滚动到第一节,而不是搜索栏。
发布于 2013-09-30 11:32:57
为了解决这个问题,我们调整了内容偏移量,以说明在iOS 7:CGPointMake(0.0, -tableView.contentInset.top)中引入的UITableView的内容嵌入
- (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;
}
}https://stackoverflow.com/questions/19093168
复制相似问题