您的位置:首页 > 移动开发 > IOS开发

IOS 取消TableView点击Cell时的色背景

2014-05-08 10:33 519 查看
为了在TableView中使用自定义的UI,所以要取消掉Cell被点击时的蓝色背景。关键代码如下:

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view.

CGRect recTableView = CGRectMake(3,102,316,324);

self.tableView =
[[UITableView alloc]initWithFrame:recTableView style:UITableViewStylePlain];

// 设置协议,意思就是UITableView类的方法交给了tabView这个对象,让完去完成表格的一些设置操作

self.tableView.delegate = self;

self.tableView.dataSource = self;

//设置TABLE VIEW背景色

self.tableView.backgroundColor = UIColor.clearColor;

//把tabView添加到视图之上

[self.view addSubview:self.tableView];

// 存放显示在单元格上的数据

NSArray *arrayCarList = [NSArrayarrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12", nil];

self.aData = arrayCarList;

[self.tableView setSectionIndexColor:[UIColor clearColor]];

[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

[self.tableView setSeparatorColor:[UIColor clearColor]];

[self.tableView setBackgroundView:nil];

//[self.tableView setAllowsSelection:NO]; //如果TALBLEVIEW为只读的话也可以直接这样写就行了

}

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

{

// 声明静态字符串型对象,用来标记重用单元格

static NSString *TableSampleIdentifier = @"BaseCell";

// 用TableSampleIdentifier表示需要重用的单元

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableSampleIdentifier];

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

cell.contentView.backgroundColor = UIColor.clearColor;

cell.backgroundColor = UIColor.clearColor;

[cell.textLabel
setHighlighted:NO];

……

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

UITableViewCell
*cell = [tableView cellForRowAtIndexPath:indexPath];

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

........

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: