Custom UITableViewCell, UITableView and allowsMultipleSelectionDuringEditing

て烟熏妆下的殇ゞ 提交于 2019-12-03 16:41:30
Lorenzo B

For those interested in, I've found a valid solution to fix the previous problem. The problem is that when selection style is UITableViewCellSelectionStyleNone red checkmarks in editing mode aren't displayed correctly. The solution is to create a custom UITableViewCell and ovverride some methods. I'm using awakeFromNib because my cell has been created through xib. To reach the solution I've followed these two stackoverflow topics:

  1. multi-select-table-view-cell-and-no-selection-style
  2. uitableviewcell-how-to-prevent-blue-selection-background-w-o-borking-isselected

Here the code:

- (void)awakeFromNib
{
    [super awakeFromNib];

    self.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"row_normal"]] autorelease];
    self.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"row_selected"]] autorelease];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    if(selected && !self.isEditing)
    {

        return;
    }        

    [super setSelected:selected animated:animated];
}

- (void)setHighlighted: (BOOL)highlighted animated: (BOOL)animated
{
    // don't highlight
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];

}

Hope it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!