使用“tableView:sectionForSectionIndexTitle:atIndex:”滚动到TableViewHeader。帮帮我? [英] Scroll to TableViewHeader using "tableView:sectionForSectionIndexTitle:atIndex:" help?

查看:981
本文介绍了使用“tableView:sectionForSectionIndexTitle:atIndex:”滚动到TableViewHeader。帮帮我?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在TableViewController的标题中添加了一个搜索栏,我还在sectionIndexTitlesForTableView数组中添加了一个{search}。现在在右侧,我得到了字母的字母+顶部的搜索符号...滚动到字母的部分(不是搜索字段)我使用了这个:

I added a search bar into my TableViewController's header, and I've also added a "{search}" to the "sectionIndexTitlesForTableView" array. Now on the right side, I got the letters of the alphabet + the search symbol on the top... to scroll to the sections of the letters (not the search field) I used this:

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{

    return index -1;
}

现在,当我点击字母A时,它会滚动到A部分,所以上。只有我不能让搜索符号滚动到tableView标题中的搜索栏...

now when I click the letter A, it scrolls to the section A and so on. Only I can't make the "search symbol" scroll to the search bar in the tableView's header...

我该怎么做?

提前感谢您...

推荐答案

如果搜索栏位于tableView的最顶部,你可以做类似的事情 -

If the Search bar is at the very top of the tableView, you could do something like-

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{

// as the search icon is at index 0, scroll to the top
    if(index == 0)    
        [tableView scrollRectToVisible:CGRectMake(0, 0, searchBar.width, searchBar.height) animated:YES];    
    return index -1;
}

否则,如果是没有任何行的部分,你可以这样做 -

Else, if it is a section without any rows, you could do-

CGRect searchBarRect = [tableView rectForSection:searchBarIndex];
[tableView scrollRectToVisible:searchBarRect animated:YES];

HTH,

Akshay

这篇关于使用“tableView:sectionForSectionIndexTitle:atIndex:”滚动到TableViewHeader。帮帮我?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆