我尝试将背景图像添加到我的UITableViewCell
。 这是我使用的代码:UITableViewCell背景图像设置
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"TableCell";
// Dequeue or create a cell of the appropriate type.
TableCell *cell = (TableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"cellbg.jpeg"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"cellbg.jpeg"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
[cell.preparationLabel setFont:[UIFont fontWithName:@"Bold" size:20]];
// Configure the cell.
if (btnselected==1)
{
cell.preparationLabel.text = [recipe.ingredients objectAtIndex:indexPath.row];
}
else
{
cell.preparationLabel.text = [recipe.preparation objectAtIndex:indexPath.row];
}
return cell;
}
我的问题是,当运行应用程序并选择实现代码如下,首先显示了默认的白色背景和一定的时间单元格背景后的表格单元格将得到改变的渴望图像......我不知道为什么它需要很长时间来加载表格视图与我想要的单元格背景
参考http://stackoverflow.com/a/15353155/1713478回答它会帮助你 – Pratik 2013-03-21 10:38:27