简体   繁体   English

UITableViewCell高亮显示覆盖了我的accessoryView

[英]UITableViewCell highlight covers my accessoryView

I have a checkbox, when its checked, it gets checkmarked. 我有一个复选框,当它被选中时,它会被勾选。 But when i select the cell, the highlight covers up the checkbox. 但是当我选择单元格时,高亮显示会覆盖复选框。 Sorry for my horrible english, but here is the code below. 对不起,我的英文很糟糕,但这里是下面的代码。 Is there a way for me to have the checkmark button on top of the highlight? 我有办法在突出显示的顶部有复选标记按钮吗?

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = nil;

if([tableView isEqual:self.myTableView]){
    static NSString *TableViewIdentifier = @"MyCells";
    cell = [tableView dequeueReusableCellWithIdentifier:TableViewIdentifier];
    if(cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableViewIdentifier];
    } 
    //configure the cell
    checkbox = [UIButton buttonWithType:UIButtonTypeCustom];
    CGRect checkboxRect = CGRectMake(135, 150, 36, 36);
    [checkbox setFrame:checkboxRect];  
    [checkbox setImage:[UIImage imageNamed:@"unselected@2x.png"]forState:UIControlStateNormal];
    [checkbox setImage:[UIImage imageNamed:@"selected@2x.png"] forState:UIControlStateSelected];
    [checkbox addTarget:self action:@selector(checkboxClicked:) forControlEvents:UIControlEventTouchUpInside];
    cell.accessoryView = checkbox;


    NSString *group;
    NSUInteger row = [indexPath row];

    switch (indexPath.section) {
        case 0:
            group = [suggestedPeople objectAtIndex:row];
            cell.textLabel.text = group;
            break;
        case 1:
            group = [aArray objectAtIndex:row];
            cell.textLabel.text = group;
            break;
        case 2:
            group = [bArray objectAtIndex:row];
            cell.textLabel.text = group;
            break;
        case 3:
            group = [cArray objectAtIndex:row];
            cell.textLabel.text = group;
            break;
        case 4:
            group = [dArray objectAtIndex:row];
            cell.textLabel.text = group;
            break;
        case 5:
            group = [eArray objectAtIndex:row];
            cell.textLabel.text = group;
            break;
        case 6:
            group = [fArray objectAtIndex:row];
            cell.textLabel.text = group;
            break;
        case 7:
            group = [gArray objectAtIndex:row];
            cell.textLabel.text = group;
            break;
        case 8:
            group = [hArray objectAtIndex:row];
            cell.textLabel.text = group;
            break;
        case 9:
            group = [iArray objectAtIndex:row];
            cell.textLabel.text = group;
            break;
        case 10:
            group = [jArray objectAtIndex:row];
            cell.textLabel.text = group;
            break;
        case 11:
            group = [kArray objectAtIndex:row];
            cell.textLabel.text = group;
            break;
        case 12:
            group = [lArray objectAtIndex:row];
            cell.textLabel.text = group;
            break;

    }
}
return cell;}

and some of my other methods: 以及我的一些其他方法:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSLog(@"cell is touched");
if(checkbox.state == UIControlStateNormal){
    [checkbox setImage:[UIImage imageNamed:@"unselected@2x.png"] forState:UIControlStateHighlighted];
}else if (checkbox.state == UIControlStateSelected) {
    [checkbox setImage:[UIImage imageNamed:@"selected@2x.png"] forState:UIControlStateHighlighted];
}}

-(void)checkboxClicked:(UIButton *)sender{
sender.selected = !sender.selected;

UITableViewCell *ownerCell = (UITableViewCell *)sender.superview;
NSIndexPath *ownerCellIndexPath = [self.myTableView indexPathForCell:ownerCell];

if(sender.selected){

}else{

}}

At the place of : 在以下地方:

[checkbox setImage:[UIImage imageNamed:@"selected@2x.png"] forState:UIControlStateSelected];

Use 采用

 [checkbox setImage:[UIImage imageNamed:@"selected@2x.png"] forState:UIControlStateHighlighted];

Might Help 可能有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM