UIAppearance を使用して、アプリ全体でテーブル セルの背景画像を設定しました。
[[UITableViewCell appearance] setBackgroundView:[ [UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"list_bg.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ]];
ただし、リストを表示すると、背景画像は画面上のセルの 1 つにのみ設定されます。画面をスクロールすると、表示されるセルに背景画像が設定されますが、この背景画像は他の表示セルに設定されません。
何が起こっているのか誰にもわかりませんか?UITableviewCell の UIAppearance を設定することで、このタイプのすべてのインスタンスが自動的に背景画像を取得すると考えました。
ありがとう
ブライアン
これが私の cellForRowAtIndexPath メソッドです:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"plantCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:@"PlantListCell" owner:self options:nil];
cell = _plantCell;
self.plantCell = nil;
}
Plant *plant = [self.fetchedResultsController objectAtIndexPath:indexPath];
UIImageView *thumbnail = (UIImageView *)[cell viewWithTag:1];
thumbnail.image = [UIImage imageNamed:[plant.name stringByAppendingString:@"_S"]];
UILabel *label = (UILabel *)[cell viewWithTag:2];
label.text = plant.name;
UIImageView *set = (UIImageView *)[cell viewWithTag:3];
set.image = [UIImage imageNamed:@"set"];
UIImageView *favourite = (UIImageView *)[cell viewWithTag:4];
favourite.image = [UIImage imageNamed:@"fav"];
return cell;
}