0
두 섹션에서 동적 행 수를 구현하는 데 어려움이 있습니다.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;
}
이 무엇을 달성하고자, 일치 (들)이 추가 만 일치하는 단어, 그리고 (내 배열은 엄격하게 알파벳 순으로 정렬) 뒤에 오는 단어, 쇼를 보여주고 있다는 것입니다 : 아래
내 코드 결과를 얻을 수 있지만 두 섹션 모두에서 동일한 결과가 표시되거나 정확히 일치하는 결과가 여러 개 표시되는 반면 추가 결과에는 단 하나의 결과 만 표시됩니다 (첫 번째 섹션과 첫 번째 섹션은 모두 일치 함).
지저분한 코드는 죄송합니다. 올바른 방향으로 안내해주세요. 감사합니다.
메리 크리스마스!