NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

(SOLVED)Project 4 - challenge 3

Forums > 100 Days of Swift

Hi everyone, thanks for your time : )

Challange: To change the initial viewController into a tableView, where the user can choose the websites to load from the list instead of loading the first one in the array upfront.

So I have 2 different View contollers. one is a tableViewController containing the list, and another is the normal ViewController that contains the website (we built this from the lecture). I added didSelectRowAt in my tableViewController. However I don't know how to load the website by clicking on a cell. I went back to project 1, where we added the below inside the detailViewController when we loaded the image by selecting the name of image :

if let imageToLoad = selectedImage {
    imageView.image  = UIImage(named: imageToLoad)
}

How do i do this with a webview? I am so lost. Now basically when i click on the cell that contains a website, my Simulator crashes, or nothing happens.

   

On the Viewcontroller's viewDidLoad, you'll do:

let url = URL(string: "https://" + selectedSite!)!
let urlRequest = URLRequest(url: url)
webView.load(urlRequest)

Or, if you want to play it safe (assuming selectedSite is an optional String):

guard let selectedSite = selectedSite else { return }

if let url = URL(string: "https://" + selectedSite)
{
  let urlRequest = URLRequest(url: url)
  webView.load(urlRequest)
}

3      

@guseulalio

OMG It is fixed! Thank you so much !!! I also found an error i made in the storyboard where i put the storyboard ID in the wrong place, hence why it was also not working.

I am so happy i could cry. This is the best feeling, THANK YOU !

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED From January 26th to 31st you can join a FREE crash course for iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a senior developer!

Save your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.