Selected UIButton disappears inside selected UITableViewCell

前端 未结 5 1807
一个人的身影
一个人的身影 2021-01-06 00:39

I have a table, I have cellForRowAtIndexPath delegate for it and I have instance of UITableViewCell being created inside that method, which I return. Somewhere in cellForRow

5条回答
  •  梦毁少年i
    2021-01-06 01:25

    It appears that the button is somehow inheriting the selected state as its highlighted state. Anyone ever find a solution to this?

    SOLUTION: I'm not exactly happy about this hack but it works for my purposes. Basically, I want the button to appear only when the cell is selected. Subclass the UITableViewCell and add these overrides (editButton is the button instance that was added to the cell's contentView in init).

    - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
        editButton.hidden = YES;
    
        [super setSelected: selected
                  animated: animated];
    
        editButton.highlighted = NO;
    
        if (selected)
            [editButton performSelector: @selector(setHidden:)
                             withObject: nil
                             afterDelay: 0.2];
    }
    
    - (void)setSelected:(BOOL)selected {
        editButton.hidden = YES;
    
        [super setSelected: selected];
    
        editButton.highlighted = NO;
    
        if (selected)
            [editButton performSelector: @selector(setHidden:)
                             withObject: nil
                             afterDelay: 0.2];
    }
    

提交回复
热议问题