0
votes

I have laid out the buttons in Interface Builder and connected them as outlets

  @IBOutlet weak var outletCatalogDetailsToolBarLink: UIBarButtonItem!

In viewDidLoad I have this:

outletCatalogDetailsToolBarLink.target = self;
outletCatalogDetailsToolBarLink.action = Selector("OwnHandleButtonClick");

The handler is defined like this:

  func OwnHandleButtonClick(Sender: AnyObject) -> Void {

However, when the button is clicked I get an error chain starting with:

unrecognized selector sent to instance

All answers I see online have the buttons created at runtime. While that is of course a solution, I would like to understand how to code against controls placed design time.

1
This is a duplicate of about 5000 existing Stack Overflow questions. Please do make an effort to search before asking. - matt
@matt - the 15+ SOs I found creates the buttons runtime which then gets accepted an answer. - Tom

1 Answers

1
votes

Change it to this:

outletCatalogDetailsToolBarLink.action = Selector("OwnHandleButtonClick:")

Mind the :.

Also, Swift doesn't require semicolons ; at the end of each line.