【问题标题】:How to remove null Values in a Table Header Objective C, Xcode如何在表头目标 C、Xcode 中删除空值
【发布时间】:2014-06-28 10:51:49
【问题描述】:

我是编码新手,刚刚开始开发新应用。几天来,我一直在寻找有关如何删除表格标题中的空标题的答案。

这是我目前的代码:

- (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 来计算我收到空值的标头数量时,我怎样才能摆脱标头中的空值?

【问题讨论】:

  • 您究竟在哪里收到空值?您的数组self.categories 是否已初始化?你设置断点显示内容了吗?
  • 如果 self.restaurant 中的 restaurant_id 与 restaurant_id 类别中的 restaurant_id 不匹配,我在标头中收到空值。也不太清楚如何设置断点来显示内容。

标签: ios iphone objective-c xcode uitableview


【解决方案1】:
- (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;
}

【讨论】:

  • 我仍然收到空白标题。在 self.categories.count 函数中,我有 482 条记录在计数。如果 restaurant_id 匹配,我希望空白标题消失。
【解决方案2】:

我相信你犯了一些非常基本的错误。正如我所看到的,您只显示那些具有[[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 字典和 self.categories 数组的日志打印。

【讨论】:

  • 我想做的是,当self.restaurant中的restaurant_id与category中的restaurant_id相同时,我想计算得到的结果数
  • 好的。我就是这么说的!
  • 你知道怎么做吗,因为这是我卡住的地方
  • 是的,为什么不呢。创建一个函数,在其中设置一个循环,创建 newArray,并将满足您条件的所有记录添加到 newArray。然后将 newArray 设为您的表数据源。
  • 能否请您通过 Skype 帮助我解决这个问题,我的 id 是jaw.khan
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-12-03
  • 1970-01-01
  • 2020-05-12
  • 2015-03-17
  • 1970-01-01
相关资源
最近更新 更多