我嘗試將背景圖像添加到我的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