- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我刚开始使用 ios,我被 UITableView
困住了。
我想在 View 的右侧实现索引栏。我已经实现了这个但是当我点击索引栏上的部分时它不起作用。
这是我的代码。这里 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 个项目的 TableView :
section index - 0 section title - 'A'
items: ['Apple', 'Ant']
section index - 1 section title - 'C'
items: ['Car', 'Cat']
然后您有 26 个部分索引标题(表格 View 右侧的索引):A - Z
现在用户点击字母“C”,您会接到电话
tableView:sectionForSectionIndexTitle:@"C" atIndex:2
您需要返回 1 - “C”部分的部分索引。
如果用户点击“Z”,您还必须返回 1,因为您只有 2 个部分,而 C 最接近 Z。
在简单的情况下,您的 TableView 中有相同的部分,因为右侧的索引有一侧可以这样做:
- (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?)
关于ios - UITableView iOS 中的 sectionForSectionIndexTitle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17548066/
我有一个带有 sectionIndexTitles 的 UITableView。这是我的数据源: let sSectionTitles = ["A","B","C","D","E","F","G","
我有一个包含完整字母表的部分索引 - 然而,我表格中的部分仅包含几个字母(例如 C、F、N、U)。 我想修改 sectionForSectionIndexTitle 以在将手指滑过部分索引时正确显示正
文档对此并不太清楚。为什么要求 UITableViewDataSource 提供索引栏部分标题的部分索引? 我的意思是...什么用例使该方法变得重要?什么时候调用它以及为什么? 最佳答案 基本上,它定
我刚开始使用 ios,我被 UITableView 困住了。 我想在 View 的右侧实现索引栏。我已经实现了这个但是当我点击索引栏上的部分时它不起作用。 这是我的代码。这里 indexArray 是
我想允许通过点击 UITableView 一侧的 sectionIndexTitles 来滚动我的 UITableView。到目前为止,我的解决方案如下: - (NSInteger)tableView
由于我是 Swift 的新手,所以我陷入了困境。我正在开发一个应用程序,我想在其中显示侧面索引部分,就像在联系人应用程序中一样。我在我的应用程序中使用了此代码 func tableView(_ tab
我正在尝试索引我的 UITableView使用以下代码 在我的 ViewDidLoad arrayOfTableView = [[NSArray alloc] initWithObjects:@"1"
嘿,有什么巧妙的方法可以使用部分索引跳转到表页眉或页脚吗?我想要的是在索引顶部添加一个部分索引,跳转到页眉,在底部添加另一个部分索引,无需滚动即可跳转到页脚。 有什么想法吗? 最佳答案 我将在 UIT
我在 TableViewController 的标题中添加了一个搜索栏,并且还在“sectionIndexTitlesForTableView”数组中添加了一个“{search}”。现在在右侧,我得到
我的 UITableView 中有数百个部分。我已将所有部分放在一个数组中,并将该数组更改为仅包含大写字母并删除了所有重复字符。 //sample array let sectionsArray: [
我在项目中使用了联系簿,所有数据显示为 sectionWise。Tableview 部分索引不显示该实现 sectionForSectionIndexTitle 和 sectionIndexTitle
我是一名优秀的程序员,十分优秀!