IBAction on button won't be called in custom keyboard

时间:2016-07-11 20:44:33

标签: ios swift ibaction custom-keyboard

I am making a custom keyboard that has a search bar. In order for a user to be able to interact with it, they must be able to:

1- Input text with individual letter buttons.

2- Tap the search button.

As for number 1, I have working IBActions that are called at every button press. For example, here's the action for the letter "m":

@IBAction func mPressed(button: UIButton) {
    searchBar.text! += "m"
}

However, the search button IBAction will not call:

@IBAction func searchPressed(button: UIButton) {
    print("searchPressed")
}

When I connect the search button in storyboard to the "mPressed" action, that action is called. But when I reconnect it back to the "searchPressed" function above, it doesn't work again.

I have also made sure that I correctly connected the button to the action.

The search action is connected to the search button

The 'm' action is connected to the 'm' button

Thanks!

1 个答案:

答案 0 :(得分:0)

In your screenshot search button connected to method searchButtonPressed, but in code you have method searchPressed.
Delete connection to searchButtonPressed and reconnect to searchPressed and it will work.