addTarget method is used to assign actions to UIControl elements in IOS.
Questions tagged [addtarget]
92 questions
0
votes
1 answer
Swift Customized UIButton unrecognized selector sent to instance
As the title says, I got this error message:
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[{Project}.{UIView} tapAction:]: unrecognized…

hanabi_noir
- 197
- 1
- 1
- 15
0
votes
1 answer
How to make UIButton hidden or not depends of UITextField
I have a button in one class and textField in another. My goal is to achieve this: when textField is empty, the button is hidden, and then I add numbers to textField (it has 4 numbers), the button becomes visible.
I add target to my button:
let…

maytime
- 111
- 1
- 12
0
votes
2 answers
UIButton addTarget doesn't get called
I'm trying to create a UIAlertController that has a UITextField inside.
The text field should have a button in its right side (using the rightView attribute). The button should view an image instead of a regular text button.
When I'm clicking the…

Ido Naveh
- 2,442
- 3
- 26
- 57
0
votes
2 answers
Adding button programmatically swift
I am trying to add button programmatically, I created button, it shows in app, but problem that when I write .addTarget in #selector occurs error (it builds successfully, but action do not work) I tried to write playAction() and playAction(sender:)…

Madiyar Kupzhassarov
- 23
- 6
0
votes
1 answer
Why a red horizontal line in code tips when I use addTarget to add events, it is
I have a UITextField and I try to use the addTarget to add a value change event, I pronounced a textFieldDidChange selector like below:
@objc private func textFieldDidChange(textFiled: UITextField) {
}
but when I tried to input some prefix code…

JonathanChen
- 9
- 2
0
votes
2 answers
How to get uitextfield to countdown from minute and seconds
My swift code below can take seconds and countdown from what is placed in the textfield.I want the user to be able to enter 5:30 and have that countdown 330 seconds. Right now for the user to do that I would have to write 330 seconds instead of…
user12418101
0
votes
1 answer
A programmatically UISlider not changing width
My swift code is all code no storyboard. My slider sx should change the width of the imagview when the value is changed. That is not happening no change is visible on the imageview. The imageview should increase / decrease when the slider value is…
user12418101
0
votes
2 answers
how to pass static parameters to a local function for UIRefreshControl() in addTarget #Selector
I have added refreshcontrol to my table view , while pulling down , it should call a local method with dictionary as parameter. But i searched a lot but couldnt send a dictionary as a parameter in addTarget of uirefreshcontrol. Please help me…

Triambagan
- 13
- 3
0
votes
2 answers
Why addTarget not calling function?
I added MTCircularSlider pod in my project.
My viewController looks like below:
class ViewController: UIViewController {
@IBOutlet var slider: MTCircularSlider!
@IBOutlet var sliderLabel: UILabel!
let temperatureArray =…

Vikas
- 1,548
- 2
- 12
- 25
0
votes
0 answers
How to fix UIButton not responding to touch?
I am working an app with quizzes, have 4 UIButtons (custom type) on subview which is custom view and none of the buttons is recognising the action even though I set the target. I have to do it programatically.
I have tried setting…

D.J.
- 1
0
votes
2 answers
Different behavior between addTarget and addGestureRecognizer
I have a function that creates a button with a selector function as a target. The address of a button gets passed to handleSelectPhoto.
lazy var image1Button = createButton(selector: #selector(handleSelectPhoto))
func createButton(selector:…

Megool
- 963
- 2
- 8
- 29
0
votes
1 answer
UIButton created from an array of strings needs a target
Here it is: I am working with some legacy code. So I can't really (feasibly) change the architecture at this point.
I have one file that creates an array of strings, in VC1:
NSMutableArray *arrButtons = [NSMutableArray array];
[arrButtons…

valeriana
- 161
- 1
- 16
0
votes
2 answers
addTarget on UIButton not working
I have a UIView class
class FloatingView : UIView {
lazy var floatingButton : UIButton = {
let button = UIButton(type: UIButtonType.system)
button.setBackgroundImage(#imageLiteral(resourceName: "ic_add_circle_white_36pt"), for:…

Sayooj
- 375
- 3
- 13
0
votes
0 answers
Expected argument type Selector [Swift]
I'm wanting to build a menu interface programically by setting up a for loop inside my main view controller which creates a bunch of buttons from a custom button class.
There are a few parameters I am passing to the button class, one of those is the…

JeremyRaven
- 119
- 1
- 10
0
votes
2 answers
UIControl addTarget(_:action:for:) Method in Swift 3.2
I have a class, let's call it ClassA, with the following addTarget call.
awesomeBtn.addTarget(nil, action: #selector(awesomeMethod), for: .touchUpInside)
The compiler accepts the above line when method awesomeMethod is in ClassA (i.e. the same…

Steve
- 696
- 7
- 15