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