Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 496 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
UIButton in Swift is not registering touches

#11
Selectors are a struct that have to be created.

Do it this way...

## Updated for Swift 4

settingsButton.addTarget(self, action: #selector(showSettings), for: .touchUpInside)

That should do it.
Reply

#12
I had the same issue when implementing UIButton and SearchBar on container view(UIView).
In my case, the cause was the constraint issue. Constraint to searchBar had issue and because of this, function set had never been called.

You can see if there's any from "Debug View Hierarchy" button. (constraint problem is shown as purple warning)

(env: iOS12, xcode10.1)
Reply

#13
I had a similar problem when i had a subViewController with buttons and tapHandlers to match, and I wanted to place this to a stack in a separate superViewController..

This cause none of the tapHandlers to to trigger, and the solution was to instead of only using addArrangedSubview(subViewController.view), I also used `addChildViewController(subViewController)` in the superview to allow the childViewController to continue to operate as a viewController and not just a view.
Reply

#14
I have had this problem when parent view of my button has `isUserInteractionEnabled == false`. All subviews will have the same `userInteraction` as their parent view. So I have just added this line `parentView.isUserInteractionEnabled = true` and the problem disappeared. Hope this helps someone.
Reply

#15
I've found similar example for Swift 2 and adapted for Swift 3. Tested it is working very well. I hope it helps.


//

[To see links please register here]

// Trevor D. Beydag

import UIKit
import PlaygroundSupport
class Responder : NSObject {
func action() {
print("Button pressed!")
}
}

let containerView = UIView(frame: CGRect(x: 0.0, y: 0.0, width: 300.0, height: 600.0))
PlaygroundPage.current.liveView = containerView
let responder = Responder()

let button = UIButton(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
button.backgroundColor = UIColor.green
button.setTitle("TEST", for: .normal)
button.addTarget(responder, action: #selector(Responder.action), for: .touchUpInside)
containerView.addSubview(button)



Reply

#16
Make sure you link you button with your IBOutlet instance variable in your code if you're using storyboard.
Reply

#17
I see it is an old question but I just faced very similar problem yesterday. My buttons were highlighted on touch but not firing the action.

I have two view controllers. One view covers the others view and button is on the top view.

eg.

- Rootviewcontroller has back view

- Topviewcontroller has top view


The button on top view does not call the action if I don't add the topviewcontroler as childviewcontroller of the rootviewcontroller. After adding the topviewcontroller as childviewcontroller it started to working.

So in short: just try to add the view controller of buttons superview as childviewcontroller to the parent views viewcontroller with the following method

func addChildViewController(_ childController: UIViewController)
Reply

#18
Old question, but thought I'd give some help to other looking for this issue. First off, I'm not entire sure this is correct so please correct me if I'm wrong.

But if you set the selector wrongly the application would crash when you press the button since it's subscribed to a selector which doesn't exist. Which means that your selector is working. My guess is that something else is blocking the touch event, assuming `UIButton.enabled = true` and `UIButton.userInteractionEnabled = true`. Usually you could check this by long pressing the button and see if it hits. If it does then you have a `UIGestureRecognizer` added somewhere which takes up the hits first. Could also be the `UIScrollView` which is delaying the touch input (there's a checkbox for this in the Inspector).

Hope this helps someone, and hope it's accurate.
Reply

#19
The problem with that tutorial from Apple is the way they put the UIView (RatingControl) inside the StackView, which is incorrect. The UIView (RatingControl) should be outside of the StackView. So, the solution is:
1. Drag the UIView (RatingControl) outside of the StackView
2. Set the constraints for the new position of the RatingControl
- Leading margin to the Container equal zero
- Trailing margin to the Container equal zero
- Top margin to the StackView equal zero

With this new constraints, now the RatingControl will have the same with as the Container, no matter what is the device screen size, and always will be just behind of the StackView where the photo selector will appear.

I hope this help you guys.
Reply

#20
So you should use following line

settings.userInteractionEnabled = true


Reply



Forum Jump:


Users browsing this thread:
3 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through