1

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

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SelectAnAlbumTableViewCellBackground"]] autorelease];
}

哪个有效,除了任何空单元格。我想知道如何设置 ALL 的背景UITableViewCell,而不仅仅是那些有数据的背景?

4

3 回答 3

3

问题是方法
`

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

仅对非空单元格调用。

所以你可以在这个方法中增加单元格的数量

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

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

于 2013-04-22T04:06:36.990 回答
1

为表格视图设置该单元格图像。

  TableView.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"Cellimage.png"]];

这是我的手机图片:

在此处输入图像描述

这是我的表格视图:

在此处输入图像描述

于 2013-04-22T04:19:35.573 回答
0

如果您需要为Cell只需使用以下行设置背景图像:

UIImageView *myImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellImage.png"]];
myImgView.frame = CGRectMake(0, 0, 300, 50);
[cell.contentView addSubview:myImgView];

通过使用此代码,您将获得获取数据原因的图像,因为只有在获取数据时才会调用。

如果你想这样做,那么你必须设置表格背景颜色。

希望这会有所帮助。

于 2013-04-22T05:27:28.150 回答