The solutions here did not help me. In most cases, it was suggested to remove the selection, but I wanted the cells to maintain the selected state. Therefore, the idea is to disable the default separator line and use your own dividing line. I tried this, but I had problems with this (you can read about it here ). The main problem was drawing a line in the accessorView . It only worked on iOS 8, but I also needed a solution for iOS 7.
My requirements:
- Selection must be kept
- The line should not disappear (especially when selecting a cell)
- The separator line above the selected cell should also not disappear.
Especially the third problem arose because of the problems, since iOS uses some kind of smoothing effect to go to the UITableViewCell to the next. As I found out, this only happens on the iPad. It has a size of about one point in each direction (the current selected cell, the cell above), so that the line on the cell disappears even if it is drawn on the cell itself (and not on the one that was used by default). It does not matter if this line is on the cell above or on the selected cell. This special effect hides my lines.
The solution is as follows:
- Use a
backgroundView where you draw two lines: one at the top (+1 point in the y direction for the iPad and 0 points in the y direction for the iPhone) and one at the bottom. Thus, it is never covered by the effect of choice. - The created background view should be used only for the selected state (
cell.selectedBackgroundView = selectedBackground ). Separator line is enabled by default for other cells.
I have a working example with the C # code posted here , although you need to adapt it to your needs. Now my choice problems are gone!
testing Dec 09 '14 at 15:48 2014-12-09 15:48
source share