问题是,这两个部分有时是空的,所以我不知道如何防止当他们变空时崩溃。 self.globalSections是由本地两个NSMutableArrays存储的全局NSMutableArrays,它们是我的UITableView的第一部分和第二部分。iOS的titleForHeaderInSection崩溃
这里是我的代码:
- (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;
}
这还好吧?
更新与崩溃日志你的问题。 – 0x8badf00d 2012-01-04 20:40:59