【问题标题】:Give the header only to specified table仅将标题提供给指定的表
【发布时间】:2013-02-27 07:35:20
【问题描述】:

我的项目中有两个 UITableView,我正在使用以下方法为一个表提供自定义标题:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if(tableView.tag == 3)
    {
    SectionInfo *array  = [self.sectionInfoArray objectAtIndex:section];
    if (!array.sectionView)
    {
        NSString *title = array.groupdeck.groupTitle;
        array.sectionView = [[SectionView alloc] initWithFrame:CGRectMake(0, 0, tblData.bounds.size.width, 45) WithTitle:title Section:section delegate:self];
    }
    return array.sectionView;
    }
    else{
        return 0;
    }

return 0;
}

它为带有标签 3 的表提供标题,例如:

但即使return 0 也将默认标题提供给其他表,否则条件如下:

我错过了什么?

【问题讨论】:

    标签: iphone xcode ipad uitableview


    【解决方案1】:

    试试:

    otherTable.sectionHeaderHeight = 0.0;
    

    您无需执行任何其他操作。

    或者:

    - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
     { 
          if(tableView.tag == 3)
          {
              //Required height.
          }
          else
          {
              return 0.0; 
          }
     }
    

    【讨论】:

      【解决方案2】:

      它可能默认为默认标头,因为您返回了 0。请尝试返回 nil

      发件人:tableView:viewForHeaderInSection: default value?

      【讨论】:

      • 嗯...然后你可以尝试设置这个:- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.0; }
      【解决方案3】:

      参考 Apple 文档中写的

       // custom view for header. will be adjusted to default or specified header height
          - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section; 
      

      显示默认标题,分组表高度为 22非分组表高度为 10

      此外,如果您要在UITableView 中显示的视图高度大于上述值,那么您还必须使用UITableView 委托方法

      - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
      

      【讨论】:

        猜你喜欢
        • 2020-12-21
        • 2010-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多