cs193p – Project #4 Assignment #4 Task #6

By DEMOSH from Nairobi, Kenya (_MG_5165) [CC BY 2.0 (http://creativecommons.org/licenses/by/2.0)], via Wikimedia Commons

Please note, this blog entry is from a previous course. You might want to check out the current one.

If the user clicks on a mentioned url in your newly created view controller, you should open up that url in Safari (see Hints below for how to do that).

Before a segue fires, check if the keyword is actually a link. If so, block it from firing and open the link instead:

    override func shouldPerformSegueWithIdentifier(identifier: String?, sender: AnyObject?) -> Bool {
        if identifier == Storyboard.KeywordSegueIdentifier {
            if let cell = sender as? UITableViewCell {
                if let url = cell.textLabel?.text {
                    if url.hasPrefix("http") {
                        UIApplication.sharedApplication().openURL(NSURL(string: url)!)                        
                        return false
                    }
                }
            }
        }
        return true
    }

The complete code for task #6 is available on GitHub.

FacebooktwitterredditpinterestlinkedintumblrmailFacebooktwitterredditpinterestlinkedintumblrmail

Leave a Reply

Your email address will not be published.