I have a “Log Out” button in the toolbar (made through the storyboard) of every screen of my app. I would like it to perform the same action no matter which page is showing when it is tapped.
Is there a way to have all these buttons do the same thing without having to create the same IBAction method in every view controller (I have a bunch of different types of view controllers)?
One solution is to share the button across all toolbars. This is both ugly and difficult. My preference is to encapsulate the logout logic in its own class and then call it from all the buttons:
Then in your view controller you can have
In this case, you still have an action in each controller, but your logout logic is not spread throughout the app.