0

アイテムのリストを含むテーブル ビューがあります。それらの項目の 1 つをクリックすると、背景が強調表示されます。そのコードは機能していますが、クリック自体ではなく、リリース時に色が変わります。ユーザーがセルを離したときではなく、セルをタップしたときに強調表示するにはどうすればよいですか?

これが私のコードです:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    // Navigation logic may go here. Create and push another view controller.

    Help_Cell *cell =(Help_Cell*) [tableView cellForRowAtIndexPath:indexPath];

    cell.selectionStyle=UITableViewCellSelectionStyleNone;

    UIView *v=[[UIView alloc] initWithFrame:cell.frame];

    v.backgroundColor=[self colorForHex:[appDel.appColorSettings objectForKey:@"cellColor2"]];

    cell.backgroundView=v;

    cell.title.textColor=[self colorForHex:[appDel.appColorSettings objectForKey:@"cellColor1"]];
}

私はそれがボタンのように起こることを望みます。onClick以外に UITableView または UITableViewCellのメソッドはありますdidSelectRowAtIndexPathか?

編集

これが私のコードですcellForRowAtIndexPath

-(void)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    Help_Cell *cell =(Help_Cell*) [tableView cellForRowAtIndexPath:indexPath];

    cell.selectionStyle=UITableViewCellSelectionStyleNone;

    UIView *v=[[UIView alloc] initWithFrame:cell.frame];

    v.backgroundColor=[self colorForHex:[appDel.appColorSettings objectForKey:@"cellColor2"]];

    cell.selectedBackgroundView=v;

}
4

2 に答える 2

2

セルの作成時に、cellForRowAtIndexPath に以下のコードを記述します。

UIView *v=[[UIView alloc] initWithFrame:cell.frame];
v.backgroundColor = [self colorForHex:[appDel.appColorSettings objectForKey:@"cellColor2"]];
    cell.selectedBackgroundView = v;

didSelectRow メソッドに何も記述する必要はありません。

于 2012-08-09T12:22:33.463 に答える
0

これをオプションと見なすことができます

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

[tableView selectRowAtIndexPath:indexPath.row animated:YES scrollPosition:UITableViewScrollPositionTop];

}
于 2012-08-09T12:28:31.133 に答える