Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.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 如何在tableview中编辑某些行高_Ios_Iphone_Tableview - Fatal编程技术网

Ios 如何在tableview中编辑某些行高

Ios 如何在tableview中编辑某些行高,ios,iphone,tableview,Ios,Iphone,Tableview,我在tableview中有15行该表是动态表,但我希望第5行和第11行的高度为20(这是幻灯片菜单中的主题菜单)。我在故事板中编辑,但它不会更改。只需将条件放在这里: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if(indexPath.row == 5){ return 20; } else{

我在tableview中有15行该表是动态表,但我希望第5行和第11行的高度为20(这是幻灯片菜单中的主题菜单)。我在故事板中编辑,但它不会更改。

只需将条件放在这里:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.row == 5){
         return 20;
    }
    else{
         return 71.0;
    }
}

在索引路径中为行执行
heights
delegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath      *)indexPath;
{
   CGFloat rowHeight = 10.0;

   if(0 == indexPath.section && (5 == indexPath.row || 11 == indexPath.row))
   {
      rowHeight = 20.0;
   }

   return rowHeight;
}

您应该在故事板中设置默认高度(更可能使用)如果要为每个单元格返回不同的高度,则应使用以下
UITableView
delegate
方法,并根据需要合并返回
UITableView单元格的高度的条件(在您的情况下,要求将第5行和第11行的高度返回为20,对于其他行,假设为50)-

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    if(indexPath.row == 5 || indexPath.row == 11)
         return 20.0;
    else
         return 50.0;
}

使用
heightforrowatinexpath:
方法。请参阅此处