テーブルのセル数は1で、各セルのセル数はUIButton
です。ボタンをクリックすると、ボタンのセルの背景色が変わります。ここにあなたの理解のための私の部分的なコードです。iOSの特定のインデックスセルの背景色を変更します。
このボタンをクリックすると、すべてのテーブルビューのセルの背景色が変更されます。どのように選択したセルのためにそれを行うには?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"SimpleTableCell";
cell = (MenuCell *)[menuTableview dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MenuViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
[cell initState];
// Listens for method calls on cell
cell.delegate = self;
}
if ((self.TempArray.count != 0)) {
for (int i=0; i<TempArray.count; i++) {
if ([self.TableviewArray objectAtIndex:indexPath.row] == TempArray[i]) {
if (cell.backgroundColor != [UIColor lightGrayColor]) {
cell.backgroundColor = [UIColor lightGrayColor];
}
UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
button.tag=indexPath.row;
[button addTarget:self action:@selector(aMethod:) forControlEvents:UIControlEventTouchDown];
[button setTitle:@"UnHide" forState:UIControlStateNormal];
button.frame = CGRectMake(200.0, 20.0, 160.0, 40.0);
[cell.contentView addSubview:button];
}
}
}
// Set index for this cell (it could be wrong if cell is re-used)
cell.downloadIndex = (int)indexPath.row;
Download *download = [TableviewArray objectAtIndex:indexPath.row];
cell.downloading = download.downloading;
cell.completed = download.completed;
cell.MenuLang.text = download.name;
cell.downLoadPrgView.progress = download.percentageDownloaded;
// Check for completed status
cell.completed = download.completed;
cell.CompletedMenuLang.text = download.name;
return cell;
}
-(void)aMethod:(UIButton*)sender {
NSLog(@"I Clicked a button %d",sender.tag);
int row = sender.tag;
}
を試してみてください。あなたのカスタムセルの背景が透明な色であることを確認してください –
私はそれがセルのために起こった..私はすべての色を変更したくない..私はちょうどボタンが選択されている特定のセルの色を変更する必要がある – RajaSasidharan
特定のセルの他のセルの色が変更されました.. – RajaSasidharan