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

时间:2013-04-01 13:42:14

标签: 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行中的一行。

你能帮忙解释为什么这样加载。

2 个答案:

答案 0 :(得分:1)

如果您将分隔符UIImage放在单元格的边界之外,并设置cell.clipsToBounds = NO;以显示分隔符图像,则可能会通过绘制下一个单元格来隐藏分隔符图像。 / p>

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

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

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

答案 1 :(得分:0)

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];
相关问题