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



我正在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,而滚动。

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

当单元格在屏幕上被绘制时,你不能控制它们的z-index,它取决于你滚动的位置(从下到上,或从上到下)。

如果这确实是你的问题,你可以把分隔符放在单元格的框架内,或者如果你的分隔符足够薄,使用:

[TableView setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:...]]];
self.tblView=[[UITableView alloc] initWithFrame:CGRectMake(0,0,320,370) //set as u need
style:UITableViewStylePlain];
self.tblView.delegate=self;
self.tblView.dataSource=self;
[self.view addSubview:self.tblView];
UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];//set as u ne
v.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"divider.png"]];
[self.tblView setTableHeaderView:v];
[self.tblView setTableFooterView:v];
[v release];

最新更新