Configuring a custom navigation bar class in the UINavigationController

I have a custom navigationBar:

class Name_UINavigationBar: UINavigationBar {
    // code
}

and I want to programmatically configure it on a navigation controller. So I tried:

var navController : UINavigationController = UINavigationController(
            navigationBarClass: object_getClass(Name_UINavigationBar),
            toolbarClass: nil)
// code

But he collapsed, saying:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
    reason: 'MyProject.Name_UINavigationBar is not a subclass of UINavigationBar'
+4
source share
2 answers

Try it.

let navController = UINavigationController(navigationBarClass: YourNavigationBar.self, toolbarClass: nil)

I ran into the same error and was able to get it working again.

+5
source

There is no supported way in Swift to get an object class. Your problem is almost certainly related to a method object_getClassthat I believe is no longer supported with Beta 5.

, API, , , , . Objective-C.

0

All Articles