Can a standard accessory view be in a different position within a UITableViewCell?

前端 未结 11 1092
谎友^
谎友^ 2020-12-05 09:57

I want my accessory to be in a slightly different place than normal. Is it possible? This code has no effect:

cell.accessoryType =  UITableViewCellAccessoryD         


        
11条回答
  •  醉酒成梦
    2020-12-05 10:25

    I was working with the ios5 and the solution given by Alexey was not working entirely. I discovered that when an accessoryType is set on a table, the accessoryView is null so the first "if" was not working. I have changed a the code just a little:

    if (self.accessoryType != UITableViewCellAccessoryNone) {
        UIView* defaultAccessoryView = nil;
    
        for (UIView* subview in self.subviews) {
            if (subview != self.textLabel && 
                subview != self.detailTextLabel && 
                subview != self.backgroundView && 
                subview != self.contentView &&
                subview != self.selectedBackgroundView &&
                subview != self.imageView &&
                subview != self.explanationButton && // Own button
                subview.frame.origin.x > 0 // Assumption: the checkmark will always have an x position over 0. 
                ) {
                defaultAccessoryView = subview;
                break;
            }
        }
        r = defaultAccessoryView.frame;
        r.origin.x -= 8;
        defaultAccessoryView.frame = r;
    
    }
    

    and this solution is working for me. As Alexey said, I don't know what is going to happen with future versions but at least in ios 4 is working.

提交回复
热议问题