我是编程新手,刚刚开始开发一个新的应用程序。几天来,我一直在寻找如何在表头中删除空头的答案。
这是我目前的代码:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view=[DetailGroupHeader loadInstanceFromNib];
NSDictionary *category = [self.categories objectAtIndex:section];
if ([[self.restaurant objectForKey:@"restaurant_id"] isEqual:[category objectForKey:@"restaurant_id"]]) {
DetailGroupHeader *headerView=(DetailGroupHeader *)view;
headerView.lblTitle.text=[category objectForKey:@"maincatename"];
headerView.btnReveal.indexPath=[NSIndexPath indexPathForRow:0 inSection:section];
}
return view;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return self.categories.count;
}在-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section的顶部,我初始化了标头的名称,这一部分工作得很好。但是,当我转到下一个函数-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView时,为了计算接收到空值的标头的数量,我如何去除标头中的空值?
发布于 2014-06-28 19:03:34
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view=[DetailGroupHeader loadInstanceFromNib];
NSDictionary *category = [self.categories objectAtIndex:section];
if ([[self.restaurant objectForKey:@"restaurant_id"] isEqual:[category objectForKey:@"restaurant_id"]]) {
DetailGroupHeader *headerView = (DetailGroupHeader *)view;
NSString *maincateName = [category objectForKey:@"maincatename"];
if ([maincateName isEqual:[NSNull null]]) {
maincateName = @"";
}
headerView.lblTitle.text = maincateName;
headerView.btnReveal.indexPath = [NSIndexPath indexPathForRow:0 inSection:section];
}
return view;
}发布于 2014-06-28 19:35:53
我相信你正在犯一些非常基本的错误。正如我所看到的,您只显示了那些[[self.restaurant objectForKey:@"restaurant_id"] isEqual:[category objectForKey:@"restaurant_id"]]条件为真的行。但是您返回的是numberOfSectionsInTableView,整个categories数组的计数为self.categories.count
我建议你检查一下:
[[self.restaurant objectForKey:@"restaurant_id"] isEqual:[category objectForKey:@"restaurant_id"]] [[self.restaurant objectForKey:@"restaurant_id"] isEqual:[category objectForKey:@"restaurant_id"]]如果您正在处理的条件确实存在,(打印日志或设置断点)这就是我目前所能说的。如果问题仍然存在,请添加self.restaurant字典和self.categories数组日志打印。
https://stackoverflow.com/questions/24466057
复制相似问题