Проблема в том, что эти два раздела иногда пусты, поэтому я не знаю, как предотвратить сбой, когда они опустеют.self.globalSections - это глобальные NSMutableArrays, хранящиеся в двух локальных NSMutableArrays, которые являются первым и вторым разделом для моего UITableView.
Вот мой код:
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (mySearchBar.text.length > 0)
{
if(section == 0)
{
//below are if statements I have tried, but not working...
//NSUInteger globalSectionsOne = [self.globalSections indexOfObject:[self.globalSections objectAtIndex:0]];
//if ([[self.globalSections objectAtIndex:0]count] >=1)
// if (globalSectionsOne!=NSNotFound)
//if (globalSectionsOne >= 1)
//{
NSLog(@"sections counts");
NSUInteger firstSectionCount = [[self.globalSections objectAtIndex:0]count];
NSString *firstSectionString = [NSString stringWithFormat:@"%i Exact match(es)", firstSectionCount];
return firstSectionString;
//}
//else {return @"";}
}
else if (section == 1)
{
//another same code, except the objectAtIndex is at 1 instead of 0.
Пожалуйста, укажите мне правильное направлениеспасибо.
РЕДАКТИРОВАТЬ:
Я изменил в этом методе:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (mySearchBar.text.length > 0 && [self.globalSections count] == 2)
{
return 2;
}
else
{
return 1;
}
//return 1;
}
Это нормально?