Best way to create ViewController

54 views Asked by At

I have an app with a TableView. TableViewCell contains a UILabel, which can contain URLs. I want these URL to open in a WebView.

Right now I'm opening Safari when user taps a link ( I'm using KILabel). What I want to do is to open these links in my app, by creating a new ViewController that contains UIWebView.

I'm wondering what is the best way to achieve it? Is it better to use storyboards or not? Do I need to create storyboard programmatically or from InterfaceBuilder?

1

There are 1 answers

0
adrienMarsden.jpeg On

There are many ways to solve this problem. Here is one solution using NSUS

  1. create a new view controller and embed a webview.
  2. create a view controller class and link the webview to that view controller class
  3. in the table view controller class, when a user taps on a url change create an IBAction that saves that URL as a NSUuserDefault like this

let defaults = NSUserDefaults.standardUserDefaults() defaults.setObject("http://www.ThisIsTheLinkThatWasClicked", forKey: "currentActiveURLKey")

4.now you can access thus URL from any view AND when the app is closed and reopened, the data is saved

  1. you can retrieve it like this

let defaults = NSUserDefaults.standardUserDefaults() if let url = defaults.stringForKey("currentActiveURLKey") { println(url) }