I have a Navigation Bar with two buttons: Back and Add. I need to transfer data (UIImage) to second View Controller (ViewControllerFilters2), when I click on the add button. I have the "prepare for segue" function but it doesn't work. When I click on "Add", I go to the second controller, but imageView doesn't have an image.
I also have another button "Apply" on view controller, and for this button this function works but not for button on navigation bar.
I tried to change my code, but I don't have a lot of knowledge to do it. And don't know, where is the problem.
I want my Add button do the same function as Apply button, i.e. I want delete Apply button and change it to Add button
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "✔", style: .plain, target: self, action: #selector(addTapped))
}
@objc func addTapped() {
let filterTwoController = self.storyboard?.instantiateViewController(withIdentifier: "filter2") as! ViewControllerFilters2
self.navigationController?.pushViewController(filterTwoController, animated: true)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let nextController = segue.destination as? ViewControllerFilters2
nextController?.filteredImage = imageView.image!
}