Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.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
UITableViewCell自定义分隔符在滚动ios8期间消失_Ios_Objective C_Uitableview_Custom Cell - Fatal编程技术网

UITableViewCell自定义分隔符在滚动ios8期间消失

UITableViewCell自定义分隔符在滚动ios8期间消失,ios,objective-c,uitableview,custom-cell,Ios,Objective C,Uitableview,Custom Cell,我已经搜索过了,但还没有找到解决方案,我有一个带有uitableviewcell的tableview。对于需要应用此自定义分隔符的单元格: UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(90, self.contentView.frame.size.height, 80, 1)]; lineView.backgroundColor = [UIColor lightGrayColor]; [self.contentView

我已经搜索过了,但还没有找到解决方案,我有一个带有uitableviewcell的tableview。对于需要应用此自定义分隔符的单元格:

UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(90, self.contentView.frame.size.height, 80, 1)];

lineView.backgroundColor = [UIColor lightGrayColor];
[self.contentView addSubView:lineView];
分隔符显示正确,现在,我不知道为什么如果我以中速上下滚动tableview,分隔符会在某些单元格上消失。我试着设定:

 - (void)layoutSubviews
{
    [super layoutSubviews];

    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(90, self.contentView.frame.size.height, 80, 1)];

    lineView.backgroundColor = [UIColor lightGrayColor];

    [self.contentView addSubview:lineView];
}

有什么建议吗?感谢

layoutSubviews
方法用于添加子视图是错误的,因为它调用了很多次。在
awakeFromNib
方法中添加此子视图

另外,由于您使用的是
self.contentView.frame.size.height
请尝试
self.contentView.frame.size.height-1,因此您的行似乎超出了单元格


此外,试着在设备上测试它,有时模拟器也会有类似的图形错误。

你还没有展示任何关于如何创建单元格的代码,但我会给出一个示例,例如,你可以这样做

//during initialisation
- (instancetype)initWithFrame:(CGRect)frame
 {
   self = [super initWithFrame:frame];
  if(self)
  {
      [self setUpCell]; 
  }
  return self;
} 

- (void)awakeFromNib
{
   [self setUpCell];
}

//hear add the views only once 
- (void)setUpCell
{
  //hear add the all views
  UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(90, self.contentView.frame.size.height - 1, 80, 1)];
  lineView.backgroundColor = [UIColor greenColor];
  lineView.tag = 123; //set its tag to access it in "layoutsubviews"
  [self.contentView addSubview:lineView];    
}

//this method may be called repeatedly, just set the frames of the subviews hear 
- (void)layoutSubviews
{
   [super layoutSubviews];
   UIView *lineView = [self.contentView viewWithTag:123]; //get the subview with tag
   lineView.frame = CGRectMake(90, self.contentView.bounds.size.height - 1,self.contentView.bounds.size.height - 1, 1);
}

您是否尝试过UIView*lineView=[[UIView alloc]initWithFrame:CGRectMake(90,self.contentView.frame.size.height-1,80,1)]?不要在
layoutSubviews
方法中添加任何子视图,在初始化过程中添加视图,并在
layoutSubviews
@ArbenPnishi中设置其框架谢谢我认为设置self.contentView.frame.size.height-1解决了我的问题!没有考虑到框架高度!