First Apps - some tips please

Hi,

I’m just having a play with my first App, mainly using the various blocks taught in the lectures in different ways.

  1. If you nest a button press inside a button press will it create a ‘second click on same button functionality’? Is there a better way of doing this?

e.g.
@IBAction func dealTapped(_ sender: Any) {
// Some code blah blah - for example ‘start something’

@IBAction func dealTapped(_ sender: Any) {
    //Some different code - for example 'stop something'

}//Close the inner
}//Close the outer

  1. Is there a good way to tie in a delay to a button press to the duration of a wav file? For example:

i. User presses button
ii. Wav file plays
iii. On completion of the wav file, the ‘next thing happens’
(iv. if you couldn’t be bothered waiting you can click again and it skips the delay…see Q1 above)

Thanks for any ideas, I don’t (think) I need code solutions, just some ideas and signposts where to look further.

Thanks

Ian

Hi Ian,

You can’t nest the same IBAction within an IBAction.

What are you trying to achieve as your explanation is not clear.

  1. No you cannot do this. Use a function to call code that does the same thing, in 2 IBActions

  2. Yes google “how to delay code”
    It has to do with DispatchQueue

Also 2, to “skip” depending if something happens or not, you need another variable to “keep track” if that thing happens

late thanks for the reply, can I ask for help on this one again please.

I have three buttons on the page, all linked to the VC on a single IBAction with a switch against tag numbers 11,22, 33

Button one works fine but buttons 2 and three don’t work. Is it obvious why in the following code? I’ve double checked they are correctly linked

@IBAction func ButtonPress(_ sender: UIButton) {

    switch sender.tag {
    case 11:
        do {
            print("button 1 pressed")
            currentPageIndex = data[currentPageIndex].b1Destination!
            soundPlayer.playSound(desiredSound: "page\(currentPageIndex)button1")
            displaySt()}

    case 22:
        do {
            print("button 2 pressed")
            // need check button is active needs an if statement
            currentPageIndex = data[currentPageIndex].b2Destination!
            soundPlayer.playSound(desiredSound: "page\(currentPageIndex)button2")
            displaySt()}

case 33:
do {
print(“button 3 pressed”)
// need check button is active needs an if statement
currentPageIndex = data[currentPageIndex].b3Destination!
soundPlayer.playSound(desiredSound: “page(currentPageIndex)button3”)
displaySt()}

    default:
        return
        
    }

Ahhh ignore me

The way the button was physically configured on the storyboard it had some invisible junk in front of it!

8 posts were split to a new topic: Compile error after Firebase Authorisation implemented