Why is the IB Action set to exit as object? - swift

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 #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.
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!

The problem might be that you are supposing you can form an action connection from a UISwitch in the scene of one view controller to a different view controller. You can't. You can form outlets and actions only between a view controller and the interface inside the same scene of the storyboard.

Click on the top bar of your problematic ViewController (the overview of what is getting displayed on screen), click the top left icon (called View Controller).
On the right click "Show The Identity Inspector" icon and you should see class. Change the text to 'ViewController'. Hopefully it should auto fill.
This will solve the problem.

Related

How to visualize if a button is set to trigger segue to another View Controller?

By holding Ctrl, clicking on a button and dragging it to another view controller, it's possible to establish the segue to move view controllers. Once this segue is created, is this connection declared somewhere in the code or in the parameters list?
I'm opening someone else's project and I can only figure out which buttons are activating which segues by running the simulation and manually testing. When I go check the code or the segue's parameters, I can't find anything that would indicate which button is linked to which view controller transition.
In Main.storyboard, click on the viewcontroller that you are interested in inspecting. In the top right there is a right arrow that will show you all the segue relationships and outlets
.
You're using Storyboards, correct?
To exemplify:
You just need to:
(1): click on the specific ViewController,
(2): then click the Connections Inspector (2) - it's icon that has an arrow with a circle around it -,
(3): and finally you'll see all the related connections (3) to that specific ViewController. This applies to all UIView(s) as well.

Go back to previous storyboard

I'm currently developing a framework in Swift that includes a storyboard that I designed myself. What I need to do is that the user that uses my framework can create a segue to my storyboard. Then I'd like to be able to recreate a segue to the user storyboard that that I "leave" my storyboard.
How could I do so ?
Thx !
Your question is vague and I am not entirely sure what you are asking. However, I can't comment yet so I will try to answer with what little I know. It seems like you are asking how to transition storyboards. The simplest way is using a UIButton in your storyboard. Open up storyboard and go to the navigation controller. Then, add a button to the Nav Controller. Right click (or control click, depending on your settings), and drag the line to the main storyboard. Lastly, click on the show option. When a user clicks on the button, it will immediately switch to the main view controller. Don't forget to add the button in the view controller. Hopefully, this is what you meant and helps. If you wish switch view controllers in code, this is a duplicate and you should go here: How to switch view controllers in swift?. If this doesn't answer your question, comment and I will try and help. For future reference, please provide more information: snippets of code, pictures, anything that better demonstrates your problem.
I fixed it by getting the instance of a new view controller added on the user storyboard with the view controller identifier like so :
ProcessOut.backViewController = storyboard?.instantiateViewControllerWithIdentifier("back")
And then I present it like I would present a normal viewController from my storyboard.

ViewController for Second View - iOS 7

I'm a beginner to iOS development, so forgive me if this is really basic. It's probably answered somewhere, but I've looked for a long time, and I'm struggling.
I have a second View on my story board that I've successfully linked to the first view using a Navigation controller and stuff, and I'm able to navigate to it. I can also add actions/outlets from elements on my first view by Control-dragging to the .h file.
I have a label on my second view, and I want to be able to do the same: add actions and outlets from elements. But when I try Control-dragging, nothing happens. What am I doing wrong, and how do I fix it?
Hmm, well first of all welcome to Stack Overflow! And thanks for asking the question.
Let me know if I have this right - you have two view controllers to the right (linked with segues) of a navigation controller and currently you can navigate to the second from the first using a button at the top right? Then when on the second view controller there's a nav button at the top left with a little arrow by it? And this should take you back to the first. Is that right?
Now on the second view controller you want to create a button that performs an action, but when you right-click-drag (ctrl-drag) onto a .h or .m file nothing happens?
If that's the case I've seen a few reasons for that. You might try:
You need to make a button, a label can only recieve actions, not create them. Read this article on IBOutlet vs IBAction
Restart Xcode (I know, it's lame, but humor me)
Make sure you're dragging (if on the .h file) between "#interface" and "#end"
Make sure you're dragging (if on the .m file) between "#implementation" and "#end"
Do you have a custom view controller class for your second view? If so, select the second view controller in your storyboard and go to the identity inspector. Set the custom class to your custom view controller's class name. Now you will be able to control-drag IBOutlets and IBActions.

Segue to another view controller with label connected crashes

I am using a storyboard to connect two different view controllers. When I click on the cell I want it to segue into another view controller (what it usually does). But anytime I link a link a label with an outlet and try to segue, it crashes.
These are some images you may need: http://imgur.com/a/N0lP6.
Thanks in advance.
Click on your terminalsviewcontroller file owner in storyboard and select the connections inspector. Check for a connection called key test that has an exclamation point next to it and delete it.

Round Rect Button connecting to ViewController.h

So, this is kind of hard for me to explain, but i will do my best. I am most likely making a simple mistake, but i cant figure it out. So, im on my mainstoryboard, with a round rect button on the controller. I open the dual view editor and open up the viewcontroller.h file. Now, i should be able to press control and drag the button connection in the .h file, but i cant. It wont give the option to. Does that make sense?
Any ideas?
http://www.youtube.com/watch?v=62Xfn5oAjw0
Edit: For example, i need to do the part at 3:08, but it won't allow me to do that.
Edit 2: Ok. So, i put the button on a single view controller, and everything worked the way it should. BUT, when i put the same button on a tab bar view controller, it doesn't play the sound it should when pressed. The sound played when it wasnt on the tab bar controller just fine though.
EDIT: I watched the video and I know what you're doing. You're trying to create an outlet. When you right click the button there'll be a circle that says "New referencing outlet". Try dragging that circle to the viewcontroller. Otherwise, just type what comes up after he does that manually. Easy.
It should already be connected automatically. You never actually drag the button to the view controller. The view should already be connected and therefore any part of the view is connected. However, if you're having problems in the future, try this to sort of start over.
What you're going to want to do is go up to file>New File
Then you're going to want to select a new view controller, and make sure you tick the box that says "Include a XIB" or something similar.
After that, it will make all the connections you need. Any part of the view will automatically connect to the view controller, and all you'll need to do is create the IB actions to preform things in the interface and connect them to buttons when you're ready.
You have to set the viewcontroller as the file owner of the view. This is done in the story board.
I don't understand why you'd want to ctrl+drag the button to your ViewController.h . If you wanted to link the button to a ViewController in the storyboard, then you just ctrl+drag it to that ViewController. I may not have understood your question, but I think this is what you want.