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.
When you attach @IBAction
s (or @IBOutlet
s), 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.
2) Hold Control (^)
and drag the button to your ViewController
class.
3) Add the button as an @IBAction
. - It's also recommended to use UIButton
as the sender, instead of Any
.
It should look like this:
If you have questions, let me know!