使用"tableView:sectionForSectionIndexTitle:atIndex:"帮助滚动到TableViewHeader?

Mar*_*man 8 iphone uitableview ios4 ios

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

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

    return index -1;
}
Run Code Online (Sandbox Code Playgroud)

现在,当我单击字母A时,它会滚动到A部分,依此类推.只有我不能让"搜索符号"滚动到tableView的标题中的搜索栏...

我怎样才能做到这一点?

先感谢您...

在此输入图像描述在此输入图像描述

Aks*_*hay 10

如果搜索栏位于tableView的最顶部,您可以执行以下操作:

- (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;
}
Run Code Online (Sandbox Code Playgroud)

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

CGRect searchBarRect = [tableView rectForSection:searchBarIndex];
[tableView scrollRectToVisible:searchBarRect animated:YES];
Run Code Online (Sandbox Code Playgroud)

HTH,

阿克沙伊