UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

(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.

3      

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)
}

6      

@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 !

5      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

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.