Search code examples
iosswifttttattributedlabeltttattritubedlabel

didSelectLinkWithURL not getting called with TTTAttributedLabel


So I'm using TTTAttributedLabel in swift and I (think I) have everything set up properly. didSelectLinkWithURL is not getting called, and I have no idea why. The link "highlight" shows up in the label - so I don't think I'm setting it up wrong.

Here's my code:

import UIKit

class ViewController: UIViewController, TTTAttributedLabelDelegate {

    @IBOutlet weak var label: TTTAttributedLabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        var str : NSString = label.text!
        let rng : NSRange = str.rangeOfString("fox")

        label.addLinkToURL(NSURL(string: "http://apple.com"), withRange: rng)

    }

    func attributedLabel(label: TTTAttributedLabel!, didSelectLinkWithURL url: NSURL!) {

        println("test123")

    }


}

Any ideas? Thanks :)


Solution

  • Add the line label.delegate = self