Ios 是否在UITableView中用数组分隔第一个字母?

Ios 是否在UITableView中用数组分隔第一个字母?,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有一个名为tableData的数组,我把它放在tableView中 tableData = [NSArray arrayWithObjects:@"Andre",@"Alessandro",@"bruno",@"caio",@"Marcio",@"Maria",@"Jose", nil]; 我们可以看到数组是按字母顺序排列的,我将此数组放在UITableView中,代码如下: - (NSInteger)tableView:(UITableView *)tableView numberOfRo

我有一个名为tableData的数组,我把它放在tableView中

tableData = [NSArray arrayWithObjects:@"Andre",@"Alessandro",@"bruno",@"caio",@"Marcio",@"Maria",@"Jose", nil];
我们可以看到数组是按字母顺序排列的,我将此数组放在UITableView中,代码如下:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [tableData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"ID HERE";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [tableData objectAtIndex:indexPath.row];
    return cell;
}
我只想在UITableView中创建一个分隔符,显示字符串的第一个字母,例如:

Letter A --> This is a separator in TableView
Andre -> this is a row
Alessandro -> This is a row
Letter B -> This is another separator
Bruno -> this is a row
Letter C -> Another separator
Caio -> this is a another row

我怎么能做到?在UITableViewDelegade中有一个方法可以为我做这件事吗?有其他解决方案吗?

尝试使用表格部分

在这里你可以找到一个教程


您必须执行两个步骤:

  • 由于您不确定是否会有完整的24个字母表字符,因此需要浏览表格数据以获得所有已存在的第一个字母的列表。注意大小写

  • 现在有两个数组,一个是tableData,左边是第一个字母的列表,我们称之为arrayFirstLetters。只需使用table部分(您可以在google上找到很多教程)


  • 我可以建议使用?找到的页面吗?我将看到此链接!