Vlad
Vlad

Reputation: 8268

TTTAttributedLabel link detection not working using Storyboard

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?

Upvotes: 3

Views: 4082

Answers (1)

Matthew
Matthew

Reputation: 867

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"];

Upvotes: 5

Related Questions