具有内容的Tableview单元格用白色覆盖?

时间:2013-11-10 12:55:08

标签: objective-c uitableview ios7

:)

我的tableview出了问题。所有具有任何内容的细胞都覆盖着白色:(

如果我按住一个单元格,我可以看到单元格标签,图像等等;浅灰色(这很好)。 如果我释放(停止按住它),单元格会按原样推送到下一个视图。

我忘记了什么?为什么我的细胞被白色覆盖?这适用于iOS 6: - )

(抱歉我的英文不好,截图也有丹麦文字; - ))

我的代码在.h:

#import <UIKit/UIKit.h>

@interface SkabelonerViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {

@private
NSMutableArray *tableData;
NSDictionary *selectedItem;

}

// Tableview stuff
@property (strong, nonatomic) IBOutlet NSArray *tabelData;
@property (strong, nonatomic) IBOutlet UITableView *tableView;

我在.m下的代码

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

UITableViewCell *cell = nil;
cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil)
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
}

UIButton *deleteButton;
deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
deleteButton.frame = CGRectMake(650, 10, 30, 30);
UIImage *image = [UIImage imageNamed:@"Trash.png"];
[deleteButton setImage:image forState:UIControlStateNormal];

[deleteButton addTarget:self action:@selector(deleteTemplate:) forControlEvents:UIControlEventTouchUpInside];
deleteButton.tag=indexPath.row;
[cell.contentView addSubview:deleteButton];

// create the label objects
UILabel *sletLabel = [[UILabel alloc] initWithFrame:CGRectZero];
sletLabel.backgroundColor = [UIColor clearColor];
//sletLabel.font = [UIFont boldSystemFontOfSize:12];
[sletLabel setFont:[UIFont boldSystemFontOfSize:12]];
sletLabel.frame = CGRectMake(654,41,25,21);
sletLabel.text =  @"Slet";
sletLabel.textColor = [UIColor whiteColor];
[cell.contentView addSubview:sletLabel];

NSDictionary *dic = [tableData objectAtIndex:indexPath.row];

cell.textLabel.text = [dic valueForKey:@"templatename"];

cell.accessoryView = [[ UIImageView alloc ]

                      initWithImage:[UIImage imageNamed:@"Right-hvid"]];

cell.textLabel.textColor = [UIColor whiteColor];
cell.selectionStyle = UITableViewCellSelectionStyleGray;

[self.tableView setBackgroundColor:[UIColor colorWithRed:37 green:37 blue:37 alpha:0]];

NSString *templateID = [dic valueForKey:@"templateid"];

deleteButton.hidden = NO;
sletLabel.hidden = NO;

return cell;
}

The view controller with my tableview:

When i press the cell:

1 个答案:

答案 0 :(得分:3)

请看一下这个问题:iOS 7中的UITableView clear background由于性能原因,UITableViewCells的默认背景颜色从clearColor更改为whiteColor

如有必要,您应该更改cell.contentView.backgroundColor = [UIColor clearColor]