7

I am seeing something really strange happening on my UITableViewCells containing UILabels with ellipsis (this project is iOS 7 only). I see the ellipsis when the tableView first load. Then, if I press a cell, the text + ellipsis colors change just as I ask it to in my setHighlighted function. But as I release it (wether as I went to the details viewController and came back to the first viewController with the table view, or just pressed and then scrolled to loose the highlight), the ellipsis disappears.

In fact, I found out that it is still there, just that it is white on the white background (the color of the highlight for the text, see the code at the bottom). For a better understanding, here are screens showing what I just described :

Before clicking :

Before clicking

The cell is highlighted while we click :

The cell is highlighted

After clicking, moving to the next viewController and pressing back :

After clicking, moving to the next viewController and pressing back

Note that if I do the click + loose the highlight by scrolling, only the cell that was highlighted looses the ellipsis. Also, when scrolling the tableView, all is fine until I reach the bottom of it, and load the next elements of the list - then all ellipsis keeps the white color (and also the highlighted font, which is bold). This lead me to believe that this is caused by something done while reloading the data of the cells.

Here is the code of setHighlighted :

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
    NSUInteger fontSize = _titleLabel.font.pointSize;

    [UIView animateWithDuration:(highlighted ? .2 : .5)
                          delay:0
                        options:UIViewAnimationOptionBeginFromCurrentState
                     animations:^{
                         _background.backgroundColor = (highlighted ? [UIColor blueND] : [UIColor whiteColor]);
                         _hourLabel.textColor = (highlighted ? [UIColor whiteColor] : [UIColor blackColor]);
                         _titleLabel.textColor = (highlighted ? [UIColor whiteColor] : [UIColor blackColor]);
                         _titleLabel.font = (highlighted ? [UIFont boldSystemFontOfSize:fontSize] : [UIFont systemFontOfSize:fontSize]);
                         _consoleLabel.textColor = (highlighted ? [UIColor blueND] : [UIColor whiteColor]);
                         _consoleLabel.backgroundColor = (highlighted ? [UIColor whiteColor] : [UIColor blueND]);
                     }
                     completion:nil];
}

Does anyone have a clue as to what is happening here ?

Thank you for your help in advance !

Update : following the comment from Leo Natan, here is the result fo po _titleLabel.attributedString for the highlighted cell, once it has been highlighted, then released :

(lldb) po _titleLabel.attributedText
Mario Golf : World Tour, le Lagon Cheep Cheep en vidéo{
    NSColor = "UIDeviceWhiteColorSpace 0 1";
    NSFont = "<UICTFont: 0x1669a990> font-family: \".HelveticaNeueInterface-Regular\"; font-weight: normal; font-style: normal; font-size: 14.00pt";
    NSParagraphStyle = "Alignment 0, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 4, Tabs (\n    28L,\n    56L,\n    84L,\n    112L,\n    140L,\n    168L,\n    196L,\n    224L,\n    252L,\n    280L,\n    308L,\n    336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
    NSShadow = "NSShadow {0, -1} color = {(null)}";
}
CyberDandy
  • 470
  • 6
  • 17
  • Is the ellipsis due to word wrap? Is it added by the system or by your code? Do you use `NSAttributedString` somewhere in the code regarding these labels? – Léo Natan Mar 14 '14 at 22:46
  • The ellipsis is automatic, using Truncate Tail for Line Breaks and Fixed Font Size for Autoshrink in the xib file. – CyberDandy Mar 14 '14 at 23:02
  • 1
    What about attributed strings? Could you reproduce the issue, then print in the bugger `po _titleLabel.attributedText` and post the output here. – Léo Natan Mar 14 '14 at 23:03
  • See my update of the question for this info. Note that the title is not an attributedString in the object it is stored in (even though I use NSAttributedStrings for other fields in my app). – CyberDandy Mar 14 '14 at 23:11
  • 1
    Any reason why you are doing this manually? You can give a label both the normal and highlighted text and background colors, and when the cell is highlighted, it will alternate between them automatically. Could be that your animation block is confusing the `CATextLayer` (the label's layer). – Léo Natan Mar 14 '14 at 23:50
  • I did not use the highlighted color because for it to work, I have to set the cell as Selectable and choose a predefined cell background color between blue and gray, and thus cannot achieve the effect I'm looking for (the one in my question). I tried it again, and the ellipsis behave normally using this, but then I cannot change my title's font to make it bold when highlighted, and, as I already said, the cell's background takes one of two default color (when I want it to stay white while I change the color of another, smaller view). – CyberDandy Mar 15 '14 at 07:41
  • 1
    Uhm, for that you have `selectedBackgroundView`, to give selected cells a background view with custom background color. – Léo Natan Mar 15 '14 at 13:15
  • Thanks for your ideas Leo, you helped me find a way to do it by setting highlighted text color, plus setting selectedBackgroundView to an empty white view with the frame of the cell. It is a workaround, but still better than nothing I guess ! If you want the vote, you could write a reply. If you don't, I'll just reply myself with some details, but I guess you earned it ! Thanks ;) – CyberDandy Mar 15 '14 at 15:27
  • Added an answer, thanks. – Léo Natan Mar 15 '14 at 15:55

2 Answers2

6

This is likely a bug with the system. Make sure to open a bug report.

As devised in the comments, instead of setting the colors manually, you can use the labels' highlightedTextColor and the cells' selectedBackgroundView to achieve what you are trying to your way.

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
0

This appears to be an apple bug. I've reported the bug (#19061268) to apple.

The current workaround I see is to set the attributed text property with the color you want instead of setting the text property.

benuuu
  • 761
  • 2
  • 7
  • 24