Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios sectionHeaderView的两种不同高度_Ios_Objective C_Uitableview - Fatal编程技术网

Ios sectionHeaderView的两种不同高度

Ios sectionHeaderView的两种不同高度,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我想在iOS应用程序中为我的sectionHeaderView设置两个不同的高度。我希望第一部分HeaderView是一个高度,第二部分和所有其他部分是另一个高度 注意:这不是表标题视图,而是sectionHeaderView 谢谢。给你举个小例子 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if (section == First

我想在iOS应用程序中为我的sectionHeaderView设置两个不同的高度。我希望第一部分HeaderView是一个高度,第二部分和所有其他部分是另一个高度

注意:这不是表标题视图,而是sectionHeaderView


谢谢。

给你举个小例子

 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
    {
        if (section == First)
        {
            return 70;
        }

        return 45;
    }

您的代码错误,请尝试以下操作:

 - (CGFloat)tableView:(UITableView *)tableView heightForViewForHeaderInSection:     (NSIndexPath *)indexPath
    {
        if(indexPath.section == 0) // First section
        {
            return 300;
        } else if(indexPath.section == 1) { // Second
            return 50;
        }
        else { // Any other section
            return 40.0; // Default
        }
  }

remove return UITableViewAutomaticDimension并尝试此代码不会编译语法错误。返回后有else语句。说真的,这更像是一个if-else问题。与iOS无关。检查一下你的代码,它只是错了。首先,您的方法不是UITableViewDelegate方法。也许这是故意的,你在以某种方式使用它。那样的话没关系。该表永远不会调用此方法。您的代码在语义上是不正确的,如果不是语法上的。您正在返回if和else块之间的UITableViewAutomaticDimension。当if的计算结果为true时,它将返回300。否则,它将返回UITableViewAutomaticDimension。你的else案例永远不会被调用。看起来这应该是有效的,但并没有改变高度。我有一个部门总部。这是不是超过了高度?
 - (CGFloat)tableView:(UITableView *)tableView heightForViewForHeaderInSection:     (NSIndexPath *)indexPath
    {
        if(indexPath.section == 0) // First section
        {
            return 300;
        } else if(indexPath.section == 1) { // Second
            return 50;
        }
        else { // Any other section
            return 40.0; // Default
        }
  }