iphone - 自定义分隔符图像在 UItableviewcell 中消失

标签 iphone ios objective-c uitableview

我正在 uitableview 单元格中加载自定义分隔符图像。

这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:    (NSIndexPath *)indexPath
{
   static NSString *CellID=@"Cell"
   MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SwitchCellIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    UIImageview *aSwitch = [[UIImageview alloc] initWithImage:[UIImage imageNamed:@"divider.png"]];
    separator.frame = CGRectMake(0,50,320,1);
    [cell.contentView addSubview:seperator];

}

if(cell.height == 22)
{
   /// here i am setting frame for uiimageview
}

但滚动时,我发现 20 行中的分隔符图像仅消失了 1 行。

您能帮忙解释一下为什么它会这样加载吗?

最佳答案

如果您已将分隔符 UIImage 置于单元格边界之外,并设置 cell.clipsToBounds = NO; 以显示分隔符图像,则分隔符绘制下一个单元格可能会隐藏图像。

当单元格在屏幕上绘制时,您无法控制它们的 z 索引,这取决于您滚动的位置(从下到上,或从上到下)。

如果这确实是您的问题,您可以将分隔板放在单元框架内,或者如果您的分隔板足够薄,请使用:

[TableView setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:...]]];

关于iphone - 自定义分隔符图像在 UItableviewcell 中消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15744620/

相关文章:

ios - 在哪里释放在同一类的不同方法中使用的 NSArray

objective-c - 自定义 View 最小尺寸

iphone - 字符串到整数的转换

ios - 将 RN FFMPEG 集成到 native react 中时出错

ios - 为什么 MPMoviePlayerController 全屏按钮图标在 iOS 10 中变为字幕图标?

objective-c - UILables、文本流和布局

iphone - 没有可见的@interface 声明选择器错误

ios - 调用保留属性时 TableViewController 崩溃?

iphone - MKMapView不会添加任何注释

iphone - UI 对象 -> 核心数据关联(子类化 UIButton,添加实例变量)