3

I am trying to integrate TTTAttributedLabel into a UITableViewCell. It's really just a simple integration and all I wanted to was to substitute the old UILabel with TTTAttributedLabel. Here's what I did.

  1. Go to Storyboard and select the UILabel inside custom UITableViewCell and change its class to TTTAttributedLabel
  2. Come back to the UITableViewController subclass, include TTTAttributedLabel.h, and modify (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath like this:

    static NSString *CellIdentifier = @"Post";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil)
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                      reuseIdentifier:CellIdentifier];
    
    TTTAttributedLabel *label = (TTTAttributedLabel *)[cell viewWithTag:801];
    label.text = [self.post valueForKey:@"content"];
    label.enabledTextCheckingTypes = NSTextCheckingTypeLink;
    label.userInteractionEnabled = YES;
    label.delegate = self;
    return cell;
    

But the link detection is not working. It's just plain text. How can I debug what I am doing wrong?

Vlad
  • 8,038
  • 14
  • 60
  • 92
  • Did you find a workaround for this Vlad? I've seen the same thing - it appears to be a timing issue. The cells are displayed before the links are able to be detected and drawn. This is evident because as the table scrolls, all future cells have the links highlighted correctly. – Codemonk Feb 26 '15 at 08:24

1 Answers1

5

I think you need to set your text after enabledTextCheckingTypes = NSTextCheckingTypeLink

label.enabledTextCheckingTypes = NSTextCheckingTypeLink;
label.userInteractionEnabled = YES;
label.delegate = self;
label.text = [self.post valueForKey:@"content"];
Matthew
  • 837
  • 7
  • 20