我正在 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/