Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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 为什么最后一个单元格';是否将UITableView的高度用于剩余的空单元格?_Ios_Uitableview - Fatal编程技术网

Ios 为什么最后一个单元格';是否将UITableView的高度用于剩余的空单元格?

Ios 为什么最后一个单元格';是否将UITableView的高度用于剩余的空单元格?,ios,uitableview,Ios,Uitableview,我的单元格都有不同的高度,由用户输入的文本决定 最后一个单元格的高度似乎决定(改变)所有剩余空白单元格的高度 对于这些剩余的空单元格,heightForRowAtIndexPath似乎没有被调用,CFRAIP也没有 有人知道如何解决这个问题或者为什么会这样吗?将此代码放在放置Tableview的viewController的ViewDiLoad中 self.tableView.tableFooterView=[[UIView alloc]init]我也遇到了这个问题。这让我很沮丧。经过一些考虑,

我的单元格都有不同的高度,由用户输入的文本决定

最后一个单元格的高度似乎决定(改变)所有剩余空白单元格的高度

对于这些剩余的空单元格,heightForRowAtIndexPath似乎没有被调用,CFRAIP也没有


有人知道如何解决这个问题或者为什么会这样吗?

将此代码放在放置Tableview的viewController的ViewDiLoad中


self.tableView.tableFooterView=[[UIView alloc]init]

我也遇到了这个问题。这让我很沮丧。经过一些考虑,我认为tableview的一个特点可能是显示空白单元格。使用空白单元格的最后一个单元格高度是合理的。否则,选择使用什么高度?
我认为显示黑色单元格是不可接受的。如果你不喜欢我这样的风格,你可以尝试以下方法来去除空白单元格:

self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; 

如果必须显示空白单元格并控制高度,那么添加其他单元格可能是最简单的方法/解决方法。例如:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   return self.dataArray == nil || self.dataArray.count == 0 ? 1 : self.dataArray + 1;
}

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.count == self.dataArray.count){ //the last cell
       cell = [[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
    } else {
       cell = .... //as uausal
    }

    return cell;
   }

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.count == self.dataArray.count){
      return 50;
   } else {
    return xxx; //as usual
   }
 }
现在我们可以控制任何高度了

希望它能帮助你


您也可以参考链接:

这很奇怪:您应该得到与可见单元格数量相同的对HFRAIP/CFRAIP的调用,无论是否为空。这不是你看到的吗?不,只是需要我真正需要的细胞。清空它在重复使用上次使用的单元格中的维度。太棒了!但是一定要纠正它。。它应该是self.tableView.tableFooterView=[[UIView alloc]init];
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.tableView.frame style:UITableViewStyleGrouped];
tableView.backgroundColor = self.tableView.backgroundColor;
self.tableView = tableView;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
   return self.dataArray == nil || self.dataArray.count == 0 ? 1 : self.dataArray + 1;
}

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.count == self.dataArray.count){ //the last cell
       cell = [[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)];
    } else {
       cell = .... //as uausal
    }

    return cell;
   }

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if(indexPath.count == self.dataArray.count){
      return 50;
   } else {
    return xxx; //as usual
   }
 }