4
UITableViewCellのコンテンツビューにボタンを追加しようとして問題が発生しています。 ボタンが見えません。しかし、セルをクリックすると、(デフォルトの青色のバックグラウンドを使用して)セルが選択されると、ボタンが表示されます。UITableViewCellのコンテンツビューにUIButtonが追加されたのは、セルが選択されたときにのみ表示されます。
テーブルビューコントローラは、initWithStyle:UITableViewStyleGrouped
で作成されます。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UIButton *theButton;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
theButton = [[UIButton alloc] initWithFrame:CGRectMake(800, 25, 32, 32)];
[cell.contentView addSubview:theButton];
theButton.tag = 1;
[theButton release];
}
if(indexPath.section ==0){
//...logic...
}else if(indexPath.section ==1){
//...logic...
}else{
cell.textLabel.text = @"some string";
theButton = (UIButton*)[cell.contentView viewWithTag:1];
[theButton setImage:theImage forState:UIControlStateNormal];
}
return cell;
}
本当に助かりました!ありがとう! – HiveHicks
うれしかったです! – tommi