HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了UITableView iOS中的sectionForSectionIndexTitle大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我刚开始使用ios,而且我遇到了UITableView.

我想在视图的右侧实现索引栏.我已经实现了这个,但当我点击索引栏上的部分时,它无法正常工作.

这是我的代码.这里indexArray是“A-Z”元素,finalArray是我的UITableView可变数组.

请告诉我应该在sectionForSectionIndextitle中实现什么.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [finalArray count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:         (NSInteger)section
{
    return [finalArray objectATindex:section];
}

- (NSArray *)sectionIndextitlesForTableView:(UITableView *)tableView
{
    return indexArray;
}

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndextitle:   (NSString *)title aTindex:(NSInteger)index
{

}

解决方法

这可能是UITableViewDatasource中最令人困惑的方法之一,最好一个例子:

假设您有一个包含4个项目的表格视图:

section index - 0 section title - 'A' 
items: ['Apple','Ant']

section index - 1 section title - 'C'
items: ['Car','Cat']

然后你有26个部分索引标题(表视图右侧的索引):A – Z.

现在,用户点击字母’C’即可接听电话

tableView:sectionForSectionIndextitle:@"C" aTindex:2

您需要返回1 – “C”部分的部分索引.

如果用户点击’Z’,您还必须返回1,因为您只有2个部分,C最接近Z.

在简单的情况下,您在表视图中具有相同的部分,因为右侧的索引可以执行此操作:

- (NSInteger)tableView:(UITableView *)tableView 
              sectionForSectionIndextitle:(NSString *)title 
              aTindex:(NSInteger)index
 {
     return index;
 }

否则取决于您的设置.您可能需要在章节标题中查找标题

NSInteger section = [_sectiontitles indexOfObject@R_625_6964@];
 if (section == NsnotFound) // Handle missing section (e.g. return the nearest section to it?)

大佬总结

以上是大佬教程为你收集整理的UITableView iOS中的sectionForSectionIndexTitle全部内容,希望文章能够帮你解决UITableView iOS中的sectionForSectionIndexTitle所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。