|
I'm on the first challenge and I manage to get the flag to spin but now the alert that shows whether their answer was correct doesn't show up. I can't figure out what is going on. Any input would be appreciated. Here is my code:
Here is the problem code:
It worked before I added this code:
|
|
It looks like flagTapped is not being called when I click on a flag. I can't figure out how to fix this. |
|
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure and A/B test your entire paywall UI without any code changes or app updates. Sponsor Hacking with Swift and reach the world's largest Swift community! |
|
The .onTapped gesture is what is preventing the flagTapped button from being called. How do I use both? |
|
Hi @morpheus! I would suggest you to look into your button structure.
If you say that you alert is not triggered but rotation works, I can assume that FlagImage structure that contains .onTapGesutre modifier overrides that tap on the button structure. The simplest way which is offered by Paul if not mistaken is to declare
then in your
|
|
Where do I declare selectedFlag? At the start of ContentView? Where do I change it in the flagTapped func?
|
|
So I changed the ForEach loop to your code:
I changed the flagTapped func to what I think its suppose to be:
The alerts work all the time now but the rotation is all over the place. Sometimes the selected flag rotates, other times multiple flags rotate. Sometimes it does not rotate at all. And on top of all that the alert covers the middle flag so you cannot see if it rotated or not. I have been stuck on this coding assignment for several days and I am getting behind. I really need help figuring this out. @ygeras has the easiest solution to implement but its just not working as expected. |
|
I think I am thinking about this wrong. The flag should spin when you click it whether its right or wrong. If that is the case I think the code works. |
|
I added a few additions to my alert to reset selectedFlag back to -1 after it spins and it appears everything is working right. |
|
yes this is exactly the idea behind it.
to solve this issue you can make alert to show up with delay in
|
|
Delayed alert:
0.5 was too fast but 1 was just right. |
|
Good point @Obelix but your code changed too much and was too hard to follow along. @ygeras code fell in line with my existing code and was easier to follow along. |
SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure and A/B test your entire paywall UI without any code changes or app updates.
Sponsor Hacking with Swift and reach the world's largest Swift community!
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.
Link copied to your pasteboard.