Ios 是否在UITableView中用数组分隔第一个字母?
我有一个名为tableData的数组,我把它放在tableView中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 = [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中有一个方法可以为我做这件事吗?有其他解决方案吗?尝试使用表格部分 在这里你可以找到一个教程
您必须执行两个步骤:
我可以建议使用?找到的页面吗?我将看到此链接!