Ios 章节标题不正确
几天来,我一直在尝试为我的Ios 章节标题不正确,ios,uitableview,Ios,Uitableview,几天来,我一直在尝试为我的UITableView设置uiTableViewHeader,但运气不佳。我想我已经不远了。目前,它显示了部分标题,但将记录数乘以X金额(我认为我的计数可能是错误的) 我想我需要进一步配置我的cellforrowatinexpath方法,但我不确定如何配置 我有点困惑。我需要将rowsAtIndexPath分组到各个部分,并阻止它们相乘 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowA
UITableView
设置uiTableViewHeader
,但运气不佳。我想我已经不远了。目前,它显示了部分标题,但将记录数乘以X金额(我认为我的计数可能是错误的)
我想我需要进一步配置我的cellforrowatinexpath
方法,但我不确定如何配置
我有点困惑。我需要将rowsAtIndexPath分组到各个部分,并阻止它们相乘
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"atozCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
//Searchbar code is here
NSDictionary *dataDict = [self.sortedArray objectAtIndex:indexPath.section];
cell.textLabel.text = [dataDict objectForKey:@"Title"];
}
return cell;
}
区段计数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [self.sectionArray count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [self.sectionArray objectAtIndex:section];
}
从中填充的数据
// Find out the path of recipes.plist
NSString *path = [[NSBundle mainBundle] pathForResource:@"law2" ofType:@"plist"];
// Load the file content and read the data into arrays
self.dataArray = [NSArray arrayWithContentsOfFile:path];
//Sort the array by section
self.sortedArray = [self.dataArray sortedArrayUsingDescriptors:@[
[NSSortDescriptor sortDescriptorWithKey:@"Section" ascending:YES],
[NSSortDescriptor sortDescriptorWithKey:@"Title" ascending:YES]]];
//Section for sorting
self.sectionArray = [self.sortedArray valueForKeyPath:@"Section"];
始终发送对象的索引。所以请试着用这个
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
return [self.tableDataIndexTitles objectAtIndex:index];
}
这是针对节索引而不是针对我的实际问题您在哪里实现了此方法-(NSString*)tableView:(UITableView*)tableView标题ForHeaderSection:(NSInteger)节在上面更新并删除了
sectionForSectionIndexTitle
,因为这只是为了测试之前的内容