首先定义一个全局变量:UIView *cellBgView;目的是避免重复创建,节约内存资源。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
staticNSString *Identifier =@"Cell";
UITableViewCell *cell = [tableViewcellForRowAtIndexPath:indexPath];
if (!cell) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:Identifier];
cellBgView = [[UIViewalloc]initWithFrame:cell.frame];
cellBgView.backgroundColor = [UIColorwhiteColor];
cell.selectedBackgroundView =cellBgView;
cell.textLabel.highlightedTextColor=EHMO_COLOR_BLUE;
}
cell.textLabel.font = [UIFontsystemFontOfSize:14];
cell.textLabel.textAlignment=NSTextAlignmentLeft;
cell.textLabel.numberOfLines=0;
tableView.separatorColor=rgb(215,215,215);
tableView.scrollIndicatorInsets=UIEdgeInsetsMake(0,0,0, -2);
if (tableView ==self.OneTable) {
self.OneTable.backgroundColor=rgb(239,239,239);
NSDictionary *dict = [oneDataArrayobjectAtIndex:indexPath.row];
cell.textLabel.text = dict[@"name"];
cell.backgroundColor=rgb(239,239,239);
}elseif (tableView ==self.TwoTable){
NSDictionary *dict = [twoDataArrayobjectAtIndex:indexPath.row];
cell.textLabel.text = dict[@"name"];
}elseif (tableView ==self.ThreeTable){
NSDictionary *dict = [threeDataArrayobjectAtIndex:indexPath.row];
cell.textLabel.text = dict[@"name"];
[cell.selectedBackgroundViewremoveFromSuperview];
}
return cell;
}