我使用下面的代码尝试在选中时使tableview单元格背景颜色清晰,并且它没有复选框,但是当它没有完全清晰的颜色时。
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
cell.tintColor = [UIColor redColor];
UIView *selectionView = [UIView new];
selectionView.backgroundColor = [UIColor clearColor];
[[UITableViewCell appearance] setSelectedBackgroundView:selectionView];
从下面的图片可以看出,它只在复选框下清除,而不是整个单元格。但是当没有复选框(不是编辑模式)时,它就完全清楚了。我怎样才能解决这个问题?提前谢谢。
如果我删除上面的代码,结果将如下所示。白色背景将覆盖整个细胞。我不知道为什么上面的代码只能为复选框下方的区域设置清晰的背景?
答案 0 :(得分:0)
添加此方法
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell setBackgroundColor:[UIColor clearColor]];
}
答案 1 :(得分:0)
我找到了解决方案,我们可以编辑下面的代码
- (void)viewDidLoad {
[super viewDidLoad];
//Add below to line
[self.tblContact setAllowsMultipleSelectionDuringEditing:YES];
[self.tblContact setEditing:YES animated:YES];
//tblContact is tableView Outlet
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//ContactTableViewCell is xib file of UITableViewCell
static NSString *identifier = @"ContactTableViewCell";
ContactTableViewCell *cell = (ContactTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"ContactTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleBlue];
cell.tintColor = [UIColor redColor];
UIView *selectionView = [UIView new];
selectionView.backgroundColor = [UIColor clearColor];
[[UITableViewCell appearance] setSelectedBackgroundView:selectionView];
cell.backgroundColor = [UIColor clearColor];
return cell;
}
答案 2 :(得分:0)
需要设置明确的单元格和单元格背景。
答案 3 :(得分:0)
如何将选择样式设置为none而不是blue?
let confDetails = storyBoard.instantiateViewControllerWithIdentifier("conferenceDetails") as! ConferenceViewController
confDetails.title = message["title"]
//Here use the code to save into plist
confDetails.conferenceDetailDict = message
self.navigationController?.pushViewController(confDetails, animated: true)