swiftxcodeibaction

Why is the IB Action set to exit as object?


I am creating an app that requires notifications. I created a settings page with a switch to toggle notifications for the application. I tried to link the switch to ViewController2 using an @IBAction, but it keeps connecting the object to Exit, instead of ViewController. I am getting really frustrated because the @IBAction won't stay connected. I am not sure what is going on, but if I could get help that would be amazing.

The images are linked down below to Imigur.

This is the connection to ViewController2

This is what occurs when I connect the IBAction to ViewController2

You can see there is no action option for the connection in this image.


Solution

  • When you attach @IBActions (or @IBOutlets), you do not want to attach them to Exit on the View Controller.

    Follow these steps to add an @IBAction:

    1) Make sure your View Controller's class is linked to your file, then go into the Assistant Editor making sure you selected Automatic.

    Using storyboards

    2) Hold Control (^) and drag the button to your ViewController class.

    Dragging item

    3) Add the button as an @IBAction. - It's also recommended to use UIButton as the sender, instead of Any.

    Connection action

    It should look like this:

    Code Send events


    If you have questions, let me know!