Iphone 关于绘制单元格矩形的解决方案的说明

Iphone 关于绘制单元格矩形的解决方案的说明,iphone,ios,Iphone,Ios,读完这篇文章后,我尝试使用这个解决方案。以下是我在tableViewDelegate方法中的代码: - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { CustomCellBackgroundView *customBackground = [CustomCellBackgroundVie

读完这篇文章后,我尝试使用这个解决方案。以下是我在tableViewDelegate方法中的代码:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
   CustomCellBackgroundView *customBackground = [CustomCellBackgroundView alloc];

    [customBackground setBorderColor:[UIColor blackColor]];
    [customBackground setFillColor:[UIColor redColor]];
    [customBackground setPosition:0]; //i'll deal with that later

    [cell setSelectedBackgroundView:customBackground];
    [customBackground release];


    UIImageView* selectedBackgroundCell = [[[UIImageView alloc] initWithFrame:CGRectNull] autorelease];
    [selectedBackgroundCell setImage:[UIImage imageNamed:@"cell_bg_50_hover.png"]];
    [customBackground drawRect:selectedBackgroundCell.frame];

    [cell setSelectedBackgroundView:selectedBackgroundCell];

    //standard background color
    [cell setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"cell_bg_50.png"]]];
}

但不幸的是,这并没有改变任何事情。你知道我做错了什么吗?

我认为无论何时制作视图,你都应该为此指定一些框架。 因此,为自定义背景和背景指定帧CGRectZero

当我测试时,下面的内容对我来说很有用

    UIView *bkview = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

    bkview.backgroundColor = [UIColor redColor];

    cell.selectedBackgroundView = bkview;

我认为,无论何时创建视图,都应该为此指定一些框架。 因此,为自定义背景和背景指定帧CGRectZero

当我测试时,下面的内容对我来说很有用

    UIView *bkview = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

    bkview.backgroundColor = [UIColor redColor];

    cell.selectedBackgroundView = bkview;

释放customBackground,然后调用[CustomBackgroundDrawRect:selectedBackgroundCell.frame]


因此,显然,在nil指针上调用函数不会有任何作用。

释放customBackground,然后调用[CustomBackgroundDrawRect:selectedBackgroundCell.frame]


因此,显然,在nil指针上调用函数不会有任何作用。

感谢您的写作。。。。我用代码修改了答案。请检查它是否有用……别忘了向bkview发送一个
自动释放
!是的,这很有效。但这不是问题的目的。如果单元格被分组,那就不好了(试试看)。这就是为什么我使用前一篇帖子(见我的第一行)感谢你的写作。。。。我用代码修改了答案。请检查它是否有用……别忘了向bkview发送一个
自动释放
!是的,这很有效。但这不是问题的目的。如果单元格被分组,那就不好了(试试看)。这就是我使用前一个帖子的原因(见我的第一行)