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

SOLVED: PROJECT 1 / TASK 3

Forums > 100 Days of Swift

Can anyone show what i should do in it ?

3      

Hey there friend!

I had the same problem, read through this thread, it might help you: https://www.hackingwithswift.com/forums/100-days-of-swift/project-1-challenge-task-3/624

I you need any further assistance, I'll do my best to help!

3      

I have seen that and need some help

3      

When i create selectedPictureNumber in DetailViewController, i can't find it in ViewController

3      

That's the point! You have to refer to it yourself. Take a look at override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {} in your main View Controller. This is the place where you refer to selectedPictureNumber and other stuff, just like this:

vc.selectedPictureNumber = indexPath.row + 1 // We add 1 to the indexPath.row because we want the selectedPictureNumber to start from 1, not 0.

You can read 'vc' up here as the Detail View Controller. So what the line above means, is:

"The property 'selectedImage' from the Detail View Controller is made by adding +1 to the indexPath.row integer of the property 'pictures', found in the main View Controller."

5      

Thank you ! You solved my problem

3      

@MateusZ One thing that I don't get is this bit of code

indexPath.row + 1

It doesn't reference to anything, right? How does it know what kind of indexPath.row + 1 it needs to ''get"? I ask this because this is the way i wrote that other variable that we needed in the challange.

            vc.totalPictures = pictures.count

As you can see it references to 'picutures'

where does this code reference to?

            vc.selectedPictureNumber = indexPath.row + 1

Little confused here.

3      

Hello,

According to Paul's instructions, in DetailViewController we create a property var selectedPictureNumber.

Also, in DetailViewController, we put this in ViewDidLoad() method:

title = "Picture \(selectedPictureNumber) of \(totalPictures)"

While totalPictures = pictures.count (which is 10), selectedPictureNumber is equal to the number of the picture's row + 1. indexPath.row is the row of the currently tapped picture in the table view controller.

So, if we tap on the FIRST picture the table view, the title of the picture will be:

Picture 1 of 10

If we didn't add + 1 to indexPath.row, the title of the first picture would be:

Picture 0 of 10

Hope that helps!

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.