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

Project 1 Challenge 3 issue

Forums > 100 Days of Swift

i have tried code blow, showing title Picture 3 of 10 but no image compleate white screen instead of picture...????

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if let vc = storyboard?.instantiateViewController(withIdentifier: "Detail") as? DetailViewController{ vc.selectedImage = "Picture (indexPath.row + 1) of (pictures.count)"

  help please ....

3      

What you did there was replace the image name (the file name) by the String "Picture 2 of 10" (or something similar).

What you need to do is set the ViewController's title property.

The code will be something like:

vc.selectedImage = pictures[indexPath.row]
vc.title = "Picture \(indexPath.row + 1) of \(pictures.count)"

3      

@guseulalio, Thank you verymuch your replay and i have tried the code you have given now picture is loading but title shows image name not "picture 3 of 10" title. here is the code i have tried...

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { if let vc = storyboard?.instantiateViewController(withIdentifier: "Detail") as? DetailViewController{

       vc.selectedImage = pictures[indexPath.row]
       vc.title = "Picture \(indexPath.row + 1) of \(pictures.count)"

        navigationController?.pushViewController(vc, animated: true)
    }

    when i tried this code is changing image name on the tableview list

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Picture", for: indexPath)
    cell.textLabel?.text = "Picture \(indexPath.row + 1) of \(pictures.count)"
    return cell
}

i dont know whats wrong with the code ....

3      

So it shows the picture but not the title? Does it show the title bar (navigation bar) at the top? What does it show?

3      

it shows title bar < storm viewer nssl0033.jpg

3      

Do you set the title somewhere else in the code?

3      

No

3      

Try cleaning the build folder.

3      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free 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.