I have created a new class to implement UITabBarControllerDelegate, but the method in the class does not been invoked.
AppDelegate.swift:
func application() {
// ...
let controller = MyTabItemController()
let tabBarController = UITabBarController()
tabBarController.viewControllers = [controller]
tabBarController.delegate = MyTabBarControllerDelegate()
self.window?.rootViewController = tabBarController
// ...
}
MyTabBarControllerDelegate.swift:
class MyTabBarControllerDelegate: NSObject, UITabBarControllerDelegate{
func tabBarController(/*...*/) {
print("method invoked")
}
}
When I selected the item, the message "method invoked" is not shown.
If I let AppDelegate extend UITabBarControllerDelegate, everything worked well and the message is shown in console.
I want to know why this happened?