UITableView separator line disappears when selecting cells in iOS7

后端 未结 24 2072
耶瑟儿~
耶瑟儿~ 2020-12-05 04:01

In my tableView I set a separator line between cells. I am allowing selection of multiple cells. Here\'s my code for setting selected cell background color:

         


        
24条回答
  •  执笔经年
    2020-12-05 04:36

    I encountered this issue when I set my cell's selection style to none programatically, and then when I SELECT my table cells programatically.

        func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: UITableViewCell!
        if tableView == self.jobLevelTableView {
            let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier", for: indexPath) as! CheckboxCell
    
            // for testing purposes
            let checked = true
    
            // I used M13Checkbox here, in case anybody was wondering
            cell.checkbox.setCheckState(checked ? .checked : .unchecked, animated: false) 
    
            if checked {
                tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
            }
    
            // CULPRIT
            cell.selectionStyle = .none
            return cell
        }
    
        cell = UITableViewCell()
        return cell
    }
    

    When I set the selection style on the storyboard (and removing the code equivalent), the problem went away!

提交回复
热议问题