Iphone UITableView所有单元格的单元格背景图像

Iphone UITableView所有单元格的单元格背景图像,iphone,ios,cocoa-touch,uitableview,Iphone,Ios,Cocoa Touch,Uitableview,我在下面的代码中将UITableViewCell的所有背景图像设置为相同的模式: - (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageName

我在下面的代码中将UITableViewCell的所有背景图像设置为相同的模式:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SelectAnAlbumTableViewCellBackground"]] autorelease];
}
除任何空单元格外,该选项都有效。我想知道如何设置所有UITableViewCell的背景,而不仅仅是其中包含数据的UITableViewCell?

问题在于方法`

仅对非空单元格调用

因此,您可以在该方法中增加单元格的数量

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
当你在有数据的单元格中时,你添加了标签或你想要的东西,但当你在空单元格中时,你什么也不做。

问题在于方法`

仅对非空单元格调用

因此,您可以在该方法中增加单元格的数量

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

当您在有数据的单元格中时,您可以添加标签或所需内容,但当您在空单元格中时,您什么也不做。

将该单元格图像设置为tableview

  TableView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"Cellimage.png"]];
这是我的手机图像:

这是我的桌面视图:


为tableview设置该单元格图像

  TableView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"Cellimage.png"]];
这是我的手机图像:

这是我的桌面视图:


如果需要设置单元格的背景图像,只需使用以下行:

UIImageView *myImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellImage.png"]];
myImgView.frame = CGRectMake(0, 0, 300, 50);
[cell.contentView addSubview:myImgView];
通过使用这段代码,你将得到它获取数据的图像,原因是它只在获取数据时调用

如果要这样做,则必须设置表格背景色


希望这会有所帮助。

如果需要设置单元格的背景图像,只需使用以下行:

UIImageView *myImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellImage.png"]];
myImgView.frame = CGRectMake(0, 0, 300, 50);
[cell.contentView addSubview:myImgView];
通过使用这段代码,你将得到它获取数据的图像,原因是它只在获取数据时调用

如果要这样做,则必须设置表格背景色


希望这会有所帮助。

cell.backgroundView=[[UIImageView alloc]initWithImage:[UIImageName:@SelectAnAlbumTableViewCellBackground.png]]自动释放];您考虑过使用分组表视图吗?这样你就不会有空的牢房了不,对于这个特定实例,我需要non-grouped.cell.backgroundView=[[UIImageView alloc]initWithImage:[UIImageName:@SelectAnAlbumTableViewCellBackground.png]]autorelease];您考虑过使用分组表视图吗?这样你就不会有空的牢房了不,对于这个特殊的例子,我需要非分组的。