jessesquires/JSQMessagesViewController

UITextView data detectors error

VincentSit opened this issue · 5 comments

Xcode 6.1 (6A1052c)
iOS Simulator iPhone 5 7.1
JSQMessagesViewController 6.0

Screenshot

ios simulator screen shot 2014 11 11 18 08 18
ios simulator screen shot 2014 11 11 18 08 23
ios simulator screen shot 2014 11 11 18 08 24

Funny this is the newest issue, as I was about to search ISSUES for it. It seems like something isn't getting reset in prepareForReuse properly, as once a data detector is used, stuff starts to randomly (guessing based on which cells are reused) get underlined. I've been seeing this for about a month but always had bigger issues to deal with first.

I've seen this too. It easily reproduces (for me) when I chat something like www.google.com. When that cell is reused for a non-link message, the underlining is retained. (Requires sending link, then filling the screen with enough to cause a scroll)

  • I see it on iOS 7.1.2, iPhone 5 and simulator
  • I do not see it on iOS 8.1 iPhone 6 and simulator

Research indicated that it might be a bug in iOS 7.x:
http://stackoverflow.com/questions/19121367/uitextviews-in-a-uitableview-link-detection-bug-in-ios-7

I implemented this work around at one point (but gave it up as it is nasty & goes against the library's "Configure almost anything on the cell" comment)

- (UICollectionViewCell *)collectionView:(JSQMessagesCollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
...
cell.textView.text = nil;
cell.textView.attributedText = [[NSAttributedString alloc] initWithString:myText attributes:@{NSFontAttributeName:myFont}];

Perhaps the library could use NSAttributedStrings on iOS 7.x, or maybe the JSQMessageData protocol could include an optional selector to retrieve an NSAttributedString which could be the favored selector for non Media Messages.

Related: #316

Per discussion in #316, the library attempts to handle this in prepareForReuse.

However, it sounds like using cell.textView.attributedText is the answer.

@walsh2000 +1 for adding NSAttributedString to the protocol.

Related to #572