2

背景として画像を持つカスタム UITableViewCell (XIB からインスタンス化) があります。ここで、セルが選択されたときに別の画像を背景にする必要があります(標準セルの青色の点滅に似ています)。setSelectedBackgroundViewin(void)setSelected:(BOOL)selected animated:(BOOL)animatedまたは inを使用して設定しようとしましdidSelectRowAtIndexPathたが、強調表示の背景が表示されません。私は何を間違っていますか?

4

3 に答える 3

3

カスタム Cell.xib で

ここに画像の説明を入力

次はこれを作る

ここに画像の説明を入力

そして最後にこうする

ここにコードを入力してください

于 2013-05-01T07:02:00.793 に答える
2

以下のように試しましたか

(cellForAtIndexPath)同じタスクを実行するための TableView DataSource メソッドから以下のメソッドを呼び出す

 - (void)setCellBGColorNormalAndSelectedForTableViewCell:(UITableViewCell*)cell cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
  UIImageView *normalCellBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];

[normalCellBG setImage:[UIImage imageNamed:@"box_nonselected.png"]];//Set Image for Normal
[normalCellBG setBackgroundColor:[UIColor clearColor]];
[cell setBackgroundView:normalCellBG];


UIImageView *selecetedCellBG = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, cell.frame.size.width, cell.frame.size.height)];
[selecetedCellBG setImage:[UIImage imageNamed:@"box_selected.png"]];//Set Name for selected Cell
[selecetedCellBG setBackgroundColor:[UIColor clearColor]];
[cell setSelectedBackgroundView:selecetedCellBG ];

 }
于 2013-05-01T07:03:03.000 に答える
1

XIB用に作成した を使用して、選択した背景ビューを設定できますCustomCell。あなたはそれを取る必要があるだけですUIImageViewXIBimageview高さと同じでなければなりませんCustomCell)。そのためのアウトレット名 " selectedBackgroundView" をCustomCellUIImageView選択した背景ビューとして取ったものに接続します。selectionStyleそのfor がCustomCellnone でないかどうかも確認します。

于 2013-05-01T06:54:03.017 に答える