How to delete null values ​​in a table header Objective C, Xcode

advertisements

I am new to coding and have just started on working on a new app. I have been stuck for a few days searching for answers on how to remove null headers in a table header.

This is my code at the moment:

- (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;
}

At the top of -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section I am initiating the names of the headers, and this part is working perfectly fine. However when I get to the next function -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView, to count the number of headers I receive null values, how can I get rid of the null values in the header?


- (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;
}