如何删除空标题标题 [英] how to remove the empty title headers

查看:96
本文介绍了如何删除空标题标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表视图,因为我有标题头,它们运行良好,但是标题头值的总和正在为空,我想在我的表视图中隐藏该空标题头.我该怎么做.请帮助我进行编码.

I am having a table view, in that I am having title headers, they are working well, but the sum of the title header values are getting null, I want to hide that null title header in my table view. how can I do this process. please help me in coding.

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [reverseOrder1 objectAtIndex:section];
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
  return 60;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 75)];
UILabel *headerTitile =[[UILabel alloc]initWithFrame:CGRectMake(20, -5, tableView.bounds.size.width-20, 75)];
headerTitile.text = [reverseOrder1 objectAtIndex:section];

headerTitile.textColor = [UIColor whiteColor];
headerTitile.TextAlignment=NSTextAlignmentCenter;
[headerView addSubview:headerTitile];
headerTitile.font = [UIFont fontWithName:@"Arial" size:16.0f];

headerView.backgroundColor = [UIColor colorWithRed:48/255.0f green:119/255.0f blue:21/255.0f alpha:1];
return headerView;
}

我变得像上面的图片一样,我想隐藏空值标题标题.

I am getting like above image,i ant to hide the null value title headers.

推荐答案

如果没有对象,则对heightForHeaderInSection进行的更改将返回0

Make changes in heightForHeaderInSection is return 0 if no objects

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
   //Note use your main array which defines section's row and according to each section it may be dictionary or array use accordingly
   NSArray *arrObjects = yourSectionsRowData[section];
   if([arrObjects count]>0])
      return 60.0;
   else
      return 0.0;
}

如果未在viewForHeaderInSection

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
   //Note use your main array which defines section's row and according to each section it may be dictionary or array use accordingly
   NSArray *arrObjects = yourSectionsRowData[section];
   if([arrObjects count]>0])
      return nil;
   else
   {
      UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 75)];
      UILabel *headerTitile =[[UILabel alloc]initWithFrame:CGRectMake(20, -5, tableView.bounds.size.width-20, 75)];
      headerTitile.text = [reverseOrder1 objectAtIndex:section];

      headerTitile.textColor = [UIColor whiteColor];
      headerTitile.TextAlignment=NSTextAlignmentCenter;
      [headerView addSubview:headerTitile];
      headerTitile.font = [UIFont fontWithName:@"Arial" size:16.0f];

      headerView.backgroundColor = [UIColor colorWithRed:48/255.0f green:119/255.0f blue:21/255.0f alpha:1];
      return headerView;
   }
}

这篇关于如何删除空标题标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆