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

SOLVED: PROJECT 1 / TASK 3

Forums > 100 Days of Swift

Can anyone show what i should do in it ?

   

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!

   

I have seen that and need some help

   

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

   

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

2      

Thank you ! You solved my problem

   

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

   

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!

   

Hacking with Swift is sponsored by RevenueCat

SPONSORED Building and maintaining in-app subscription infrastructure is hard. Luckily there's a better way. With RevenueCat, you can implement subscriptions for your app in hours, not months, so you can get back to building your app.

Try it for free

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

Reply to this topic…

You need to create an account or log in to reply.

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.