
我想在视图的右侧实现索引栏.我已经实现了这个,但当我点击索引栏上的部分时,它无法正常工作.
这是我的代码.这里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:Title]; if (section == NSNotFound) // Handle missing section (e.g. return the nearest section to it?)总结
以上是内存溢出为你收集整理的UITableView iOS中的sectionForSectionIndexTitle全部内容,希望文章能够帮你解决UITableView iOS中的sectionForSectionIndexTitle所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)