gpt4 book ai didi

iOS UITableViewStylePlain 部分和行问题

转载 作者:行者123 更新时间:2023-11-29 04:52:16 25 4
gpt4 key购买 nike

我在两个部分中实现动态行计数时遇到了麻烦。

我的代码如下:

- (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;

}

我想要实现的是,精确匹配仅显示匹配的单词,以及它后面的单词(我的数组严格按字母顺序排序),显示在其他结果中,但我得到的只是它显示相同的单词两个部分中的结果,或者它在完全匹配中显示多个结果,而在附加结果中仅显示一个结果(与第一部分中的第一个匹配相同)。

抱歉,代码困惑,请指出正确的方向,谢谢。

圣诞快乐!

最佳答案

因为有 2 个节,所以 numberOfRowsInSection 将运行 2 次,你应该在 numberOfRowsInSection 的开头使用 if 或 switch,用不同的节号做不同的工作,这会让你在不同的节得到正确的答案。

关于iOS UITableViewStylePlain 部分和行问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8619893/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com