Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/40.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_Iphone_Uitableview - Fatal编程技术网

Ios 当单元格具有自定义高度时,如何自定义UITableView分隔符

Ios 当单元格具有自定义高度时,如何自定义UITableView分隔符,ios,iphone,uitableview,Ios,Iphone,Uitableview,我跟随这篇文章: 问题是,当我为我的手机设置了自定义高度时,它不能很好地工作 我将向您展示两幅图像,一幅有两行的图像是我的单元格有一个自定义高度的结果 使用自定义高度: 嗨,问题出在cellForRowAtIndexPath方法中,你的单元格还不知道它的高度。如果您使用自定义高度(您知道此高度,请在cellForRow中使用此高度…) 例如: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndex

我跟随这篇文章:

问题是,当我为我的手机设置了自定义高度时,它不能很好地工作

我将向您展示两幅图像,一幅有两行的图像是我的单元格有一个自定义高度的结果

使用自定义高度:


嗨,问题出在cellForRowAtIndexPath方法中,你的单元格还不知道它的高度。如果您使用自定义高度(您知道此高度,请在cellForRow中使用此高度…)

例如:

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 49.0, cell.contentView.frame.size.width, 1)];

lineView.backgroundColor = [UIColor darkGrayColor];
[cell.contentView addSubview:lineView];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
另外,别忘了可以使用separatorStyle和separatorInset,以便在这一行中自定义一个litle。如果不使用,请将其设置为“无”:

   self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

自定义高度是一个单元格还是所有单元格?是否有自定义单元格?在笔尖里?问题在于,设置线视图后,单元会展开。如果你想让它粘到底部,你可以查看autoresizingMask或设置autoLayout Constraints这看起来很有希望,我回到办公室后会测试它,谢谢!Onik的答案是正确的,只有一件事——更好,如果您不硬编码布局,而是重写UITableViewCell layoutSubviews函数,并将类似于
self.lineView.frame=CGRectMake(0,self.frame.size.height-1,self.frame.size.width,1)的内容放在那里
   self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;