UITextViews in a UITableView link detection bug in iOS 7

后端 未结 13 799
醉梦人生
醉梦人生 2020-12-01 07:19

I have custom UITableViewCells that contain a UITextView. I have link detection in the UITextView turned on in Interface Builder. When I first load the table view, everythin

13条回答
  •  生来不讨喜
    2020-12-01 08:01

    It seems that setting the text to nil before setting the new text doesn't work. You also might need to be able to scroll the text view, so setting the scrollEnabled might not be an option.

    However, it works when you create and set an attributed string to the cell's text view. I used a collection view, but it should be the same with table views. I wrote the following lines in the collectionView:cellForItemAtIndexPath:

    //get the color and other properties from your UITextView
    UIColor *textColor = cell.textView.textColor;
    UIFont *messageFont = cell.textView.font;
    
    //create your attributed string
    NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:yourStringForTheTextView attributes:@{NSForegroundColorAttributeName:textColor, NSFontAttributeName:messageFont}];
    
    //set it to your UITextView
    cell.textView.attributedText = attributedString;
    

    Hope this helps :).

提交回复
热议问题