Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build An iTunes Search App Building the User Interface Implementing a Search Bar

Argument of '#selector' refers to instance method 'dismissSearchResultsController()' that is not exposed to Objective-C

UPDATE: Found problem.

https://stackoverflow.com/questions/36818083/selector-refers-to-a-method-that-is-not-exposed-to-objective-c

@objc func dismissSearchResultsController() {
        self.dismiss(animated: true, completion: nil)
    }

Everything was going great for me up until this step. I can't seem to shake this error message and I'm not entirely sure where to start. I've checked file names, watched the video twice and this error keeps repeating.

import UIKit

class SearchResultsController: UITableViewController {



    override func viewDidLoad() {
        super.viewDidLoad()

        self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(SearchResultsController.dismissSearchResultsController))


    }

    func dismissSearchResultsController() {
        self.dismiss(animated: true, completion: nil)
    }

}

UPDATE: Found problem.

https://stackoverflow.com/questions/36818083/selector-refers-to-a-method-that-is-not-exposed-to-objective-c

@objc func dismissSearchResultsController() {
        self.dismiss(animated: true, completion: nil)
    }

1 Answer

Since #selector uses an underlying ObjC method we have to explicitly declare that in the dismiss SearchResultsController function.

@objc func dismissSearchResultsController() {
        self.dismiss(animated: true, completion: nil)
    }