0
2つのセクションで行の動的カウントを実装するのに問題があります。iOS UITableViewStylePlainセクションと行の問題
以下マイコード:私が達成したい何
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (mySearchBar.text.length > 0)
{
if(section == 0)
{
return @"Exact match(es)";
}
else
{
return @"Additional results";
}
}
else
{
return @"";
NSLog (@"No sections!");
}
}
- (NSInteger)tableView:(UITableView *)tableView1 numberOfRowsInSection:(NSInteger)section
{
if (mySearchBar.text.length > 0)
{
NSMutableIndexSet *mindexes = [[NSMutableIndexSet alloc] init];
NSMutableArray *firstSection = [[NSMutableArray alloc]init];
NSMutableArray *secondSection = [[NSMutableArray alloc]init];
NSUInteger i;
for (i = 0; i <= [self.filteredListContent count] ; i++)
{
// NSLog (@"mysearchbar text %@", mySearchBar.text);
// NSLog (@"self.filtered text %@", [self.filteredListContent objectAtIndex:i]);
//if ([mySearchBar.text isEqualToString: [self.filteredListContent objectAtIndex:i]])
//NSRange s = [mySearchBar.text rangeOfString: [self.filteredListContent objectAtIndex:i]];
//if (s.location!=NSNotFound)
//{
//[mindexes removeAllIndexes];
//[firstSection removeAllObjects];
[firstSection addObjectsFromArray:[self.filteredListContent filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(SELF beginswith[c] %@)", mySearchBar.text]]];
//[firstSection addObject:[self.filteredListContent objectAtIndex:i]];
NSUInteger ind = [firstSection indexOfObject:[self.filteredListContent objectAtIndex:i]];
[mindexes addIndex:ind];
/*
if (section == 0)
{
return [firstSection count];
[tableView reloadData];
}
*/
[self.filteredListContent removeObjectsAtIndexes:mindexes];
//}
//else //if (!(mySearchBar.text == [self.filteredListContent objectAtIndex:i]))
//{
//[secondSection removeAllObjects];
//[secondSection addObject:[self.filteredListContent objectAtIndex:i]];
//secondSection = [NSMutableArray arrayWithArray: firstSection];
//[secondSection removeObjectsAtIndexes: mindexes];
// [self.filteredListContent removeObjectsAtIndexes:mindexes];
/*
if (section == 1)
{
return [secondSection count];
[tableView reloadData];
//return [self.filteredListContent count];
}
*/
//}
}
if (section == 0)
{
return [firstSection count];
//[tableView reloadData];
}
if (section == 1)
{
//return [secondSection count];
return [self.filteredListContent count];
//[tableView reloadData];
//return [self.filteredListContent count];
}
NSLog (@"if return");
}
else // if (mySearchBar.text == nil)
{
//[total release];
return [self.noWords count];
NSLog (@"else return");
}
*/
//Add a return 0; at the end of your method. It's basically a failsafe, if none of the if conditions are met.
return 0;
NSLog (@"return 0!!!");
//If you want to make sure one of the conditions is met, return -1; should cause the application to throw an exception and crash, which might help you track down errors.
//return -1;
}
、完全一致(ES)が唯一マッチした単語を示しており、それの後に来る単語が(私の配列は厳密にアルファベット順に並べている)ということで、追加でショー両方のセクションで同じ結果が表示されるか、正確な一致でいくつかの結果が表示されますが、追加結果では1つの結果(最初のセクションと最初の一致が同じです)のみが表示されます。
ご迷惑をおかけして申し訳ありませんが、正しい方向に指してください、ありがとうございます。
メリークリスマス!