I've faced this issue many many times, and I can't wrap my head around what's wrong with it.
Here's the code :
struct dataSource {
let menu = MenuView()
static var array = NSArray(contentsOfFile: Bundle.main.path(forResource: "Australie", ofType: "plist")!)!
init() {
}
func getDicoSection(sectionNumber: Int) -> NSDictionary {
var dico = NSDictionary()
dico = dataSource.array[sectionNumber] as! NSDictionary
return dico
}
func getNumberOfRootSections() -> Int {
return dataSource.array.count
}
func setMenu(delegate: MenuViewDelegate, menuView: MenuView, rootView: UIView, navigationController: UINavigationController, navigationItem: UINavigationItem) {
let menuButton = UIBarButtonItem(title: "test", style: .plain, target: self, action: #selector(dataSource.menuButtonSelected))
navigationController.navigationBar.isTranslucent = false // permet de faire en sorte que la view ne soit pas derrière la navigationBar
navigationController.navigationBar.barTintColor = UIColor.red
navigationItem.rightBarButtonItem = menuButton
print(menuButton)
MenuView().delegate = delegate
rootView.addSubview(menu)
menu.backgroundColor = UIColor.lightGray
}
func menuButtonSelected() {
print("OK")
}
}
On my button I add a selector for the action to call when it's pressed. Which is a simple print("OK").
However, Swift asks me to put @objc in front of my method. Why ? I have absolutely no idea why. But I'm resilient with XCode, so I obey. I add @objc. But as you can see, it doesn't resolve anything at all : https://drive.google.com/open?id=0B-AByLCqlbVBcG95SFhTOE1sMzA
I think I'm going to need to go to a mental clinic after that.