iOS UITableViewStylePlain节和行问题
我在两个部分中实现动态行计数时遇到问题 我的代码如下:iOS UITableViewStylePlain节和行问题,ios,uitableview,nsarray,row,Ios,Uitableview,Nsarray,Row,我在两个部分中实现动态行计数时遇到问题 我的代码如下: - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { if (mySearchBar.text.length > 0) { if(section == 0) { return @"Exact match(es)";
- (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;
}
-(NSString*)表视图:(UITableView*)表视图标题标题标题部分:(NSInteger)部分{
如果(mySearchBar.text.length>0)
{
如果(节==0)
{
返回@“完全匹配”;
}
其他的
{
返回@“其他结果”;
}
}
其他的
{
返回@”;
NSLog(@“无节!”);
}
}
-(NSInteger)表视图:(UITableView*)表视图1行数节:(NSInteger)节
{
如果(mySearchBar.text.length>0)
{
NSMutableIndexSet*mindexes=[[NSMutableIndexSet alloc]init];
NSMutableArray*firstSection=[[NSMutableArray alloc]init];
NSMUTABLEARRY*secondSection=[[NSMUTABLEARRY alloc]init];
NSUI;
对于(i=0;i因为有2个区段,所以numberOfRowsInSection将运行2次,您应该在numberOfRowsInSection的开头使用if或switch,使用不同的区段号执行不同的作业,这样可以在不同的区段获得正确的ans