UIButton in UIStackView button click is not working - ios

In UIViewController I have subview of UIView inside that I have a UIStackView like the below hierarchy:
UIView -> UIStackView -> UIView -> UIView -> UIButton
The UI which I design is working perfect but the button click is not working. I have created a IBAction but the click event is not working. I have checked the form nothing is helped me. Is anything should I need to do additionally?
How can I enable the button click event?
My button click Action
#IBAction func buttonClicked(_ sender: Any) {
print("Button Clicked")
}
My sample UI

Please check following -
User interaction of each superview.
IBAction for all buttons.
If you are still having issue then let me know. Happy coding

Check the Action connected to it and class of the object, if not rewire the thing or remove and drag a new object. Also check the constraints.

Related

Is it possible to link two buttons to two different ibactions in the same ViewController?

i work on a project and i have two buttons, one for sending a mail and the second one is an imagepicker.
I've able to link my first button to my #IBAction sendMail but I can't do the same with my #IBAction imagePicker.
When i do a "drag and drop" from the storyboard to the interface file my ViewController nothing happens. The blue strip is here but no window pop up to create the link..
A bit of help would appreciate.
Here is the code :
internal class ViewController : UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override internal func viewDidLoad()
#IBAction internal func
sendEmail(_ sender: any)
#IBAction internal func
imagePicker(_ sender: UIButton)
}
You may have already solved it, but the problem may originate because you are viewing the file interface instead of the file.
On your storyboard, touch the yellow circle of your ViewController.
Then touch the button with the 2 rings in the top right corner of the xCode:
Now change from automatic to manual:
Finally, find your ViewController without (interface) in the name and connect de action there.
If you did it all rigth, now you can see a white circle in the left of your action like this:

TouchDown from UIControl Never Called

I have changed my view to a UIControl in order to add a TouchDown recognizer (that way I can dismiss isEditing in my UITextView). I have also added an outlet to a function in my class. All my other outlets work, but when I touch down this never gets called. Could it be because my Control has many things layered on top of it? Any other idea why?
#IBAction func userTappedBackground(_ sender: Any) {
bioTextView.endEditing(true)
}

Control-drag in Xcode gives outlets, but no action for UIButton. Why?

In my app I'm building, I've got a Navigation Controller with a View Controller connected as a subview (is that the right word?). I added a UIButton and tried to Control-drag it into my view controller class file, but it's only giving me Outlet and Outlet collection as my options, not Action.
Screenshot of what I'm seeing
It's a pretty simple app, and I've tried removing my Pods as a fix, but so far no luck.
I've also tried manually writing the function and trying to connect it back to the button, but to no avail. Dragging back to the button in the workspace doesn't work, and the function isn't firing when I test the app. Here's the code I tried:
#IBAction func tapSaveButton(_ sender: UIButton) {}
It's probably something simple, so what am I missing here?
EDIT: Also, here's how I'm set up. I have a Navigation Controller with a UINavigationItem that shows a sub ViewController. The button in question is in the sub ViewController and I setup a new swift file to handle that ViewController's class. I'm trying to connect that button into that class file, and that's where it's not working.
Screenshot of my storyboard
Here's my ViewController class's code:
import Foundation
import UIKit
import KeychainSwift
class SettingsViewController : UIViewController {
let keychain = KeychainSwift()
#IBOutlet weak var APIKeyField: UITextField!
#IBOutlet weak var WebSocketIPField: UITextField!
#IBOutlet weak var SettingsSaveButton: UIButton!
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
/* My other code, not related */
}
#IBAction func tapSaveButton(_ sender: UIButton) {
// My button actions here.
}
}
Of course it was something dumb. I removed the class from the button, and viola, it let me create an action in my Swift file.
maybe you tried to connect to other viewcontroller
please check again it is correct viewcontroller and connected on storyboard exactly
Right click on the uibutton within storyboard, you should see a list of action options under "Sent Events" the most common one to use is "Touch Up Inside".
Drag from the one you want (circle to the side) onto your view controller and everything should work fine.
EDIT: For clarity, you can even drag from "Touch Up Inside" to the func you've already created so long as it's labeled
#IBAction ...
which your code already has done.
It's also happen with me, when i added localization in my project, from that time which storyboard was added in localization, that storyboard buttons are not showing any action option, only showing outlet options.

UIButton cannot clicked after adding to another uiview

I try to make the slideshow using uiscrollview, it will be triggered by slide event from uiscrollview.
Everything works fine except I try to add uibutton to the view, the button can be added and shown in the view but when I try to click the button, it does not triggered the function that I have stated in the addTarget function.
Anyone knows how to triggered the function assigned to the button?
First Create func:
func messagePrint(_ sender:UIButton) {
print("function called")
}
Then addTarget into UIButton:
btnDemo.addTarget(self, action: #selector(messagePrint(_:)), for: .touchUpInside)
In Above code btnDemo is UIButton Outlet.

How do I perform a push segue from an imagePickerController?

I've wired up a next button that sits on top of an imageView. My imagepicker sets the returned image to the imageView and I want to segue by pressing the IBAction. However when I press it, it doesn't perform the segue. I can see the button is being pressed, so I cant therefore understand why the segue isn't working. Does anyone know why?
#IBAction func nextPage(sender: AnyObject) {
self.performSegueWithIdentifier("showCaptionpage", sender: self)
}
Just drag imagePickercontroller to new Viewcontroller and select push. if you are using newer xcode version then push is deprecated. you can select show.

Resources