gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 03:08:41 26 4
gpt4 key购买 nike

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

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

return index -1;
}

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

我该怎么做?

提前致谢...

enter image description here enter image description here

最佳答案

如果搜索栏位于 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;
}

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

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

HTH,

阿克谢

关于iphone - 使用 "tableView:sectionForSectionIndexTitle:atIndex:"帮助滚动到 TableViewHeader?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6994480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com