Hello again this is Caleb with Deb's slopes dot com and in this video we're going to go ahead and create
some dummy data to load into our table view.
We're going to create six instances of you image load in our images from our assets and then we're going
to create an array of names to go with each cell based on the item in the picture.
So go ahead and pull open your project right click on accelerometers on and click new file.
This can be a swift file.
Click next.
And I'm just going to call this maybe images plus names.
OK.
And that will create a nice file here images plus names got swift and I just closed my assistant editor
there because I don't need it.
And so now we're going to create six instances of UI image passing in the data from our assets.
And so because of that we're going to need UI kit to deal with UI image so passen you ikat And now go
ahead and create some properties.
Var camera.
OK if you remember we have an image of a camera.
And I know this but you don't necessarily need to have this memorized but the file name for the camera
image is one.
So we can type you image and there is a way to create a UI image from its file name.
So go ahead and type UI image named.
And we're going to just pass in the Name one.
OK.
Now this is a way to make an optional UI image but since we know for sure that we have a file with that
name we're going to force unwrap it.
We're going to do the same thing here I'm actually going to copy and paste this five times.
One two three four five and I'm just going to update the name and the number with the proper image.
So number two was city.
OK so let's replace city there with number two animal.
I'll just say that maybe animals.
OK that will be number three flowers was number four the next one was the standard the flower Stansel.
Just call it stand and number six was the urban scene.
And that's Number Six kind of an inner city basketball scene.
Pretty cool.
Now what we're going to do is we're going to create an array and just pass in all these images so type
var image array equals and go ahead and pass them all in camera city animals flowers stand and urban.
OK.
Now since this is declared outside of any class we have access to it all throughout our project which
is pretty amazing.
Next we're going to go ahead and create an array of strings that are capitalized that go with each of
these technically I guess we could use the variable names but I'd rather just use string values.
So go ahead and type var name array and go ahead and create an array like so.
And we're going to create some strings so you can create the quotes there and a comma.
And I'm actually just going to go ahead and copy and paste this five times just like I pasted the variables.
OK.
Now since the first item is camera that's going to be a cell that would show camera.
Maybe if this was a shopping app cameras then maybe city than animals than flowers.
After that we'll be stands like maybe we can show people the nearest flower stands.
And then Urban looks like I added a little bit too many there.
And beautiful.
So now we have data.
We have our images and we have the names that go along with them.
So we're now at a great point to go ahead and set up our table view.
So go into list table view controller and for the number of cells we can return the number of items
in the image array.
So go ahead and type return whip's return.
Image array
image array count and if you build and run you'll see that we do have access to that because it's not
defined in any class so we have access to it universally.
Now what we're going to do is we're going to go ahead and create a cell and we're going to go ahead
and use our parallax cell reuse identifier to actually use that.
So go ahead and safely create a cell by typing guard let sell equals table view.
Dequeue reusable cell with identifier What's the identifier boom parallax cell.
So go ahead and type that para lacks cell K for index path.
We get that from our function.
So pass in the index path for that cell and we need to actually explicitly cast this as an instance
of parallax cell by using an optional unwrap or not unwrapping an optional casting there.
So if for some reason this doesn't work we're going to go ahead and return an empty table view cell
just like that.
OK.
So now we have an instance of parallax cell that's being reasonably Decoud from our table view which
is want to learn more about that I would recommend that you go look it up it really really cool stuff.
And now all we need to do is call sell and configure sell with you I image and description.
Check it out.
That's our function.
Now where are we going to get the UI image.
This this function here self-growth index path.
If you don't remember basically what it's doing is it's looping through our table view we said hey there
is as many cells as there are items in this array.
So there are six items for each of those items.
It's going to go ahead and create a cell.
It's going to loop through and it's going to go ahead and set a cell for each of those items that we
said there is.
So what we can do is actually we can use the same count let's say that our index path is zero.
So the first item is that path 0 we want to pull out the image at path zero as well.
And the description at path 0.
So what we can do is we can say hey I want to go into the image array and I want to pull out the item
an index path dot row because that's that's actually the numbers 0 for the image array.
So I can pull out the for the cell at row 0.
I can plot the image at row 0 and the name using name array.
So go ahead and call name array and then type index path dot row.
And now we have an image from the image array and we have a description from the name array at the exact
right place for ourselves.
Pretty cool stuff.
So now all we need to do now that we have properly configured it is simply type return cell and check
it out that air goes away it stops yelling at us.
How rude.
And now we can build our app and we can go check it out.
So build and run the app is going to go ahead and build to my phone and I'll show you in quick time
and just a moment as soon as it opens.
But yeah guys we are super duper close in the next video we're going to write the function that's going
to allow us to actually use our parallax effect with the accelerometer and gyroscopes.
Very cool stuff.
So pull it open here and we actually were just getting a black screen.
I'm getting that on my phone too.
And it appears that we have not set a starting visi.
That's right.
Remember at the beginning of this section we deleted the initial table or the initial view controller
and replaced it with the table view controller.
So to fix this problem just select the view controller and then tick the box.
Initial view controller in the attributes inspector so ticked that box and you'll see that little arrow
pops up there.
Now we can build and run and pull open the simulator and see everything that we want to see hopefully.
Let's let's check it out.
So let's pull up in the simulator here and oh look at that.
There's our images there is our labels.
Everything looks amazing guys so good.
All right.
So we are super duper close to getting our parallax effect in there so let's actually head over to the
next video.
Let's write the parallax function and we're going to call it on all the image views in this cell.
So let's head over to the next video and let's do that now.