【发布时间】:2012-01-04 20:26:55
【问题描述】:
问题是这两个部分有时是空的,所以我不知道如何防止它们变空时崩溃。 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;
}
这样好吗?
【问题讨论】:
-
使用崩溃日志更新您的问题。
标签: ios uitableview title