Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set custom navigation bar class in UINavigationController

I have a custom navigationBar :

class Name_UINavigationBar: UINavigationBar {
    // code
}

and I want to set it to my navigation controller programmatically. So I tried :

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

But it crash saying :

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
    reason: 'MyProject.Name_UINavigationBar is not a subclass of UINavigationBar'
like image 423
anasaitali Avatar asked Sep 09 '14 10:09

anasaitali


1 Answers

Try this.

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

I encountered the same error and was able to get it working again like that.

like image 147
Isuru Avatar answered Oct 19 '22 12:10

Isuru