Santanu Karar
Santanu Karar

Reputation: 1076

+[UIView onBackgroundRequest:]: unrecognized selector sent to class

Deployment target: 8.4 Swift: 2.0

I have UIViewController class which has an UITableView and an UIView as it's tableHeaderView. UIViewController class has an UINotification listener, and the UIView which used as tableHedearView dispatches an UINotification.

My UIViewController class is fairly simple.

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)
    }
}

In runtime, whenever the method (onBackgroundRequest) fires upon a button tap in StartTableHeaderView and it dispatches the UINotification, I'm hitting with the following error:

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'

Upvotes: 0

Views: 686

Answers (1)

stevekohls
stevekohls

Reputation: 2255

How is the action on your button in class StartTableHeaderView that calls onBackgroundRequest: set up? Are you using Interface Builder or doing it in code? If in code, can you post that?

I think you may not be posting the notification like you think. Put a breakpoint inside StartTableHeaderView onBackgroundRequest: and see if it is ever triggered.

The error is telling you that onBackgroundRequest: is not found, not onBackgroundRequested:.

Upvotes: 1

Related Questions