Displaying images on another view controller when button is clicked

Swift 4

First, add a notification in each button action:

NotificationCenter.default.post(name: Notification.Name("buttonAIsPressed"), object: nil)

now add a notification listener in the viewDidLoad of the collection view class and call the function in the selector:

 NotificationCenter.default.addObserver(self, selector: #selector(self.YourFunctionName), name: Notification.Name("buttonAIsPressed"), object: nil)

now whenever a button is pressed the function you named will be called.

Leave a Comment