Question

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?

Was it helpful?

Solution 2

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.identity inspector Now you will be able to control-drag IBOutlets and IBActions.

OTHER TIPS

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:

  1. You need to make a button, a label can only recieve actions, not create them. Read this article on IBOutlet vs IBAction

  2. Restart Xcode (I know, it's lame, but humor me)

  3. Make sure you're dragging (if on the .h file) between "@interface" and "@end"

  4. Make sure you're dragging (if on the .m file) between "@implementation" and "@end"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top