部署目標:8.4 夫特:2.0+ [UIView的onBackgroundRequest:]:無法識別的選擇發送到類
我有具有的UITableView和的UIView,因爲它是tableHeaderView
UIViewController類。 UIViewController類有一個UINotification監聽器,UIView作爲tableHedearView
調度一個UINotification。
我的UIViewController類非常簡單。
StartViewController(的UIViewController):
class StartViewController: UIViewController, UINavigationControllerDelegate
{
@IBOutlet weak var tblContents: UITableView!
override func viewDidLoad()
{
super.viewDidLoad()
// table header view
let headerView = StartTableHeaderView(frame: CGRectMake(0, 0, tblContents.bounds.width, self.view.frame.height*0.3))
tblContents.tableHeaderView = headerView
// adds notification listener
NSNotificationCenter.defaultCenter().addObserver(self, selector: "onBackgroundRequested:", name: "changeBackground", object: nil)
}
func onBackgroundRequested(notification:NSNotification)
{
let uiImagePicker = UIImagePickerController()
uiImagePicker.delegate = self
uiImagePicker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
self.presentViewController(uiImagePicker, animated: true, completion: nil)
}
}
extension StartViewController: UIImagePickerControllerDelegate
{
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
{
...
}
}
StartTableHeaderView(的UIView):
class StartTableHeaderView: UIView
{
...
@IBAction func onBackgroundRequest(sender: AnyObject)
{
NSNotificationCenter.defaultCenter().postNotificationName("changeBackground", object: nil)
}
}
在運行時,無論何時該方法(onBackgroundRequest)觸發後一butto n輕觸在StartTableHeaderView並分派UINotification,我有以下錯誤擊球:
2015-10-06 17:31:00.738 Elmo[1838:55864] +[UIView onBackgroundRequest:]: unrecognized selector sent to class 0x3272d90 2015-10-06 17:31:00.745 Elmo[1838:55864] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[UIView onBackgroundRequest:]: unrecognized selector sent to class 0x3272d90'
你需要'removeObserver'當對象重新分配 –
我有這個在我的課,雖然: 'DEINIT { NSNotificationCenter.defaultCenter()removeObserver(個體經營)。 }' –
在您似乎試圖調用onBackgroundRequest UIView類的方法,並有一個在你發佈的代碼...... –