我有一個表格視圖控制器,一個滑動手勢識別器,只要用戶向上滑動就會觸發NSNotificationCenter.defaultCenter().postNotificationName("DuskTheme", object: nil)
。爲什麼我的NSNotificationCenter拋出異常?
在viewDidLoad中()函數,我有以下觀察者:NSNotificationCenter.defaultCenter().addObserver(self, selector: "dusk:", name:"DuskTheme", object: nil)
它調用改變所述元件的電流視圖控制器上的顏色(即主題)的函數dusk(notification: NSNotification)
。
我想改變我的導航欄的顏色,以及當用戶刷卡,所以我子類的navigationController並添加了以下觀測到其viewDidLoad中():NSNotificationCenter.defaultCenter().addObserver(self, selector: "dusk:", name:"DuskTheme", object: nil)
還有dusk(notification: NSNotification)
功能包含了新的顏色我從Storyboard鏈接的導航欄。
這裏是我的自定義導航控制器類:
class customNavigationController: UINavigationController {
@IBOutlet weak var featuredNavBar = ThemeManager.navigationbar
override func viewDidLoad() {
super.viewDidLoad()
//Adding a theme notification observer
NSNotificationCenter.defaultCenter().addObserver(self, selector: "dusk:", name:"DuskTheme", object: nil)
func dusk(notification: NSNotification) {
UIView.animateWithDuration(1, animations: {
UIApplication.sharedApplication().statusBarStyle = .LightContent
self.featuredNavBar?.barTintColor = UIColor(red: 69/255, green: 69/255, blue: 69/255, alpha: 1)
})
}
}
}
現在,出於某種原因,每當表視圖控制器刷卡應用程序引發以下異常:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TestApp.customNavigationController dusk:]: unrecognized selector sent to instance 0x7939c910'
這是錯誤所引起的手勢識別器?在繼承導航控制器之前,它工作正常。更重要的是,檢測主題已更改並更改導航欄顏色的更好方法是什麼?
提前致謝!
如果'黃昏()'沒有參數,將選擇器更改爲'黃昏',擺脫':'。 – vacawama
@vacawama修正了上面的代碼 – cyril
'func dusk(notification:NSNotification)''customNavigationController'內的頂層方法(即它不在另一個函數裏面,比如'viewDidLoad')? – vacawama