0

試してみたい、セルをクリックすると色が変わり、クリックしたセルに色が残るはずです。ここまでは成功しました。しかし、テーブルが更新されると、セルの背景色が消えてしまいます。これについて私を助けてください私はこれを使用するアップルドキュメントからコードを取得しました。コードのいくつかの行がありません

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

   if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

      //here i create view with color for cell when cell is click this view should display as background i am write or wrong by doing this please help me here why my view is disappear when my tableview is refresh then this view is disapper from cell i want to stay that place till user not click other cell&mt tableview is grouped tableview.
       UIView *v = [[[UIView alloc] init] autorelease];
       v.layer.cornerRadius =6.0f;
       v.backgroundColor = [UIColor darkGrayColor];
       cell.selectedBackgroundView = v;
       }
     return cell;
}



- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0 || indexPath.row%1 == 0) {
        UIColor *altCellColor = [UIColor colorWithWhite:0.2 alpha:0.1];
        cell.backgroundColor = altCellColor;

    }


}
4

1 に答える 1

0

更新時に選択した行を保持したい場合は、選択した indexPath を保存し、次の方法を使用できます。

NSIndexPath *rowToSelect; //save your selected indexPath

[myTableView selectRowAtIndexPath:rowToSelect animated:YES scrollPosition:UITableViewScrollPositionNone;
[myTableView scrollToRowAtIndexPath:rowToSelect atScrollPosition:UITableViewScrollPositionNon animate:YES];
于 2012-06-05T06:23:57.993 に答える