Can't connect IBAction in Xcode

前端 未结 12 1560

When I drag from a button on the storyboard to my view controller Swift file, I only get the option to insert an Outlet or Outlet Collection.

Similarly, if I create the

相关标签:
12条回答
  • 2021-02-02 13:19

    I was having the same issue but it was because I was trying to connect an ImageView to an IBAction (forgive me, not sure if my terminology is correct). I deleted the ImageView object and replaced it with a Button and IBAction then became an option rather than just IBOutlet and Outlet Collection.

    0 讨论(0)
  • 2021-02-02 13:21

    For me, I was trying to connect multiple buttons to one IBAction, none of the solutions worked until I switched my method signature to specify that the sender was a UIButton rather than Any

    @IBAction func buttonPressed(_ sender: UIButton) {
    }
    
    0 讨论(0)
  • 2021-02-02 13:23

    This apparently is a known issue on the Apple forums, but I don't know if Apple is working on it:

    https://forums.developer.apple.com/message/216258

    Here is what I did for a workaround.

    1. Go into my Podfile and comment out the pod library (in my case, ReactiveKit Bond) that is doing an extension causing the issue.
    2. Do a pod update to remove the pod from the project.
    3. Go back in and do my IBAction connections in IB like I normally would. Do as many together as possible for efficiency.
    4. Finally go back and uncomment your pod library and do another pod update to reimport the pods.
    5. Test by setting a breakpoint in your new IBAction functions to verify your connections are working.
    0 讨论(0)
  • 2021-02-02 13:26

    I can't speak to the underlying cause--something always seems to be breaking in XCode, but you can always write your IBAction manually, @IBAction func(sender: UIButton) { } in your view/controller and then control-drag from the storyboard element to the action itself. If that doesn't work try linking from the node created by an IBAction in the margin of your code back to the storyboard. This works for me when XCode stops working.

    0 讨论(0)
  • 2021-02-02 13:27

    Alright, it's 2019 and this problem still happens and if anyone is here still looking for a solution, the only way i could get it to work is to:

    • Write your IBAction function in the extension
    • In Interface Builder, tap File's owner or the main view
    • On the Right toolbar click on the Connections Inspector

    • go down the list and find the IBAction you created, sitting there all alone and not connected to anything
    • Click on the empty circle next to it and drag to your sad sad button

    • See that sad button is now happy again and connected to something
    0 讨论(0)
  • 2021-02-02 13:33

    For me, it was a FUIButton (custom from SAP Fiori) causing same issue. No pods or UIButton extension specified in my own code (in addition to SAP UIButton obviously). Cmd + Alt + Shift + K, DerivedData Clean didn't help either. @IBAction wasn't available in Interface Builder till I changed my Button Class back to simple UIButton.

    And... voila! ta-da!

    0 讨论(0)
提交回复
热议问题