Search code examples
objective-ciosmodel-view-controlleribaction

iOS Development - How to receive button event from a custom view controller class?


So I've got this "save" button in my main view controller that I would like to move into a different view controller (WriterViewController). After doing this, my custom view controller class isn't able to respond to any of the button events. Not sure what im doing wrong here but here some screenshots:

Save button is first in my main view controller. I'll be moving it to the view controller to the right (WriterViewController).

Save button is currently in the main view controller.

As you can see, after moving the button into the intended view controller, the view controller has a custom class set to "WriterViewController".

enter image description here

I then ctrl + click and drag the save button so that i can link up it's "Touch Up Inside" event to the "saveEntry" method.

enter image description here

A screenshot of my WriterViewController.h file.

enter image description here

And the implementation.

enter image description here

Doing the same exact step for the main view controller did work and i was able to log my message. However, it wouldn't work for the custom view controller.

Any thoughts?

Thanks for reading!


Solution

  • Why not just make the save button from scratch for WriterViewController? It's not hard to drag out a UIButton and set it's text to "Save."

    Regardless, have you clicked on the button in the scene and viewed the connection's inspector to make sure the connections are what you'd expect? It seems obvious, but sometimes the connections can get all screwed up if you forget to clean them up. (ie. you copy a button over, connections and all, and things don't act as you think they should.)