感谢您提前帮忙。
尝试按照此解决方案按字母顺序对UITableView进行自动分组:yasirmturk solution但是我被困在这个部分,他说:
按字母过滤后:
NSArray *sectionArray = [vendorList filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [self.sections objectAtIndex:section]]];
rowCount = [sectionArray count];
问题:我应该在哪里放置NSArray * sectionArray代码?更具体地说?
当前状态:Current Status (repeated array without filtering)
预期结果:
1)“蛋本尼迪克特”应在“E”部分下,“火腿和蛋三明治”在“H”部分下。
答案 0 :(得分:1)
在
中添加它- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(self.isFiltered){
NSArray *filteredSectionArray = [filteredTableData filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [arrSectionsHeader objectAtIndex:section]]];
return [filteredSectionArray count];
}
else{
NSArray *sectionArray = [allTableData filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [arrSectionsHeader objectAtIndex:section]]];
return [sectionArray count];
}
}
和
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//....
if (isFiltered) {
NSArray *filteredSectionArray = [filteredTableData filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [arrSectionsHeader objectAtIndex:indexPath.section]]];
cell.nameLabel.text =[filteredSectionArray objectAtIndex:indexPath.row];
}else{
NSArray *sectionArray = [allTableData filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", [arrSectionsHeader objectAtIndex:indexPath.section]]];
cell.nameLabel.text = [sectionArray objectAtIndex:indexPath.row];
}
//....
}
=)