首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableView区段索引无法滚动到搜索栏索引

UITableView区段索引无法滚动到搜索栏索引
EN

Stack Overflow用户
提问于 2013-09-30 11:32:57
回答 1查看 2.3K关注 0票数 5

在iOS7之前,我们在UITableView索引的顶部添加了一个放大镜图标,方法是在节索引标题前加上UITableViewIndexSearch

通过拖动到节索引中的放大镜图标,tableView可以使用以下代码滚动到searchBar:

代码语言:javascript
复制
- (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中,这只会滚动到第一节,而不是搜索栏。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-30 11:32:57

为了解决这个问题,我们调整了内容偏移量,以说明在iOS 7:CGPointMake(0.0, -tableView.contentInset.top)中引入的UITableView的内容嵌入

代码语言:javascript
复制
- (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;
    }
}
票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19093168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档