Match Card Game Lesson 5

I’ve gone through the lesson exactly as Chris has stated, when I run the app I get this error and have no idea what it means/how to fix it. Any help would be greatly appreciated.
Cheers,
Jason

So I have solved a couple of the problems that I’ve run into, the latest one is this… Suggestions on why this is happening?

At a guess I’d say there is an issue with your CollectionView CardCell constraints.

ok, thank you chris, i’ll go back and double check. I was able to solve it by by unchecking automatic sizing somewhere (can’t remember where at the moment and don’t have Xcode on this laptop) but wonder if that’s just going to cause a problem later one…? Also even though sizing is fixed doing what I did, there is no scrolling of the screen to see all the cards. I can’ only see 2 rows.

Clearly there is something else not set correctly. The nature of a collectionView is to scroll automatically if there is more cells below or above the ones currently visible.

Is your cellForRowAt code the same as this?

I will look at this when I get home this eve from work. Thank you for your quick responses and assistance, it’s much appreciated.
Having a quick look at your screen, I do think I recognize something that isn’t on mine [indexPath.row}, I don’t recall seeing the “.row”, will check though.
Thanks again,
cheers,
Jason

1 Like

If ‘row’ was missing in [indexPath.row] you would have a subscript error…

ah, ok. I’ll review screen with mine and reply back to this thread tonight or tomorrow with some screen shots if I continue to have problems.
Thank you!

1 Like

Downloaded Xcode onto the laptop :slight_smile:
this is a screenshot of from my Match Card Game project. I think it’s from the same section as yours. It definitely has some differences but I thought I did exactly as what was done up till the end of Lesson 5 so far. I’ll have to check to make sure I didn’t miss anything. Are you seeing a clear error Chris?

Ah, I was forgetting that that you have not completed all the videos in the series so obviously you are still part the way through. The point you are up to is probably correct though you may have missed something if the output on your simulator is different to what Chris has at that point in the video.

What you saw in my screen shot is how that method looks when the App is completed.

You may have to go back and check that you didn’t miss anything even though that is a slow process.

on to the next problem Chris… hahaha suggestions on why my cards won’t flip? It’s identical to the code in the video for lesson 8. I went through some of the debugging suggestions mentioned in lesson 6 or 7 and have a print statement in like he does in that video but that doesn’t even show up when the code is run. so i’m at a loss here.

Hmmmmm, what does your UI look like at the moment in your simulator? Do you have a correctly displayed set of cards that have the backs showing?

In your viewDidLoad() do you have the two lines of code:

collectionView.delegate = self
collectionView.dataSource = self

I do have all the cards displaying properly. My connections to the cards is correct. For some reason the background won’t stretch across the entire screen, i’ve checked all the constraints on it as well and the size of the image but it doesn’t seem to change. As you can see it’s just all white except at the very bottom where you can see the background.

in the viewDidLoad() those 2 lines are there and correct.

I do really appreciate your time trying to help!

The background not stretching could be fixed by setting the image to “Scale To Fill” in storyboard. But that’s a minor issue at the moment.

Your view hierarchy is slightly different to mine so not sure if that has any bearing on your issue. In that hierarchy view mode you can tap on the layers and on the right of your screen in the Object Inspector you can identify what each layer is. In your screenshot there is the background color and then in front of that you should have the StackView, then UICollection view, then CardCollectionViewCell (4 per row), then a UIView (4 per row) then on top the UIImageView (4 per row).

While you are in storyboard make sure that User Interaction Enabled is checked for each of the layers (select each in turn) View, StackView, Collection View and CardCell. I’m pretty sure they should be checked by default but it’s worth checking nevertheless.

Oh, one other thing. Have a look at your Background setting for your Collection View. What is yours set to? Mine is set to Clear Color which will allow the background image to blend through.

I checked to make sure all user interactions where checked and they were, thank you for that suggestion though. Wouldn’t have known to look at that. I changed the background to “scale to fit”, that solved that issue of not reaching the ends. Changed the collection view background to clear colour and now it shows black…
still unable to tap on the cards and have them flip, but making some progress on the glitches thanks to you. Interesting how you have a stack view and I don’t but that could come in a later lesson. I haven’t completed them all yet, cause it bothers me that I can’t get it to work the way it should at the end of each lesson. Don’t want to move on and complicated it more before having it work the way it’s suppose to at that point.

Ah yes I can’t remember if the stackView came later. Probably did so that he could add the timer Label which you will learn about in time. The fact that you can’t tap on the cards and have them flip is puzzling at this point in the project.

In your didSelectItemAt method in ViewController do you have the line: let card = cardArray[indexPath.row]?

If that is missing there is nothing to tie the card to the cell.

Hi Chris, I do have that line of code in place. I’ve rewatched a few lessons just to confirm and I don’t see any difference between mine and Chris’s. Maybe if you run my code you’ll find something…
but it doesn’t seem that I can attach a file here, just images.
if you know how let me know and I’ll attach my xcodeproject for this game.

Morning Jason,
(Well it’s morning here in Perth, Western Australia)
The only way you can post your project is to upload it to, maybe, Google Drive and then post a link to it here. I’ll download it and take a look. Nothing else to do while stuck at home so that will keep me occupied. :sunglasses:

I could upload it to dropbox and share the link…

Let me know if this works and if you find anything…


I hear ya on being stuck at home, I’m in Toronto, Canada and we are getting close to full on martial law it seems. People getting tickets for being in public parks…
Cheers,
Jason