Questions tagged [addtarget]

addTarget method is used to assign actions to UIControl elements in IOS.

92 questions
2
votes
1 answer

About addTarget for a button inside a UITableViewCell

I'm not able to understand why the addTarget in my UIButton is not working in a specific case. So, there is a UITableViewCell where I create a button programmatically, like: let myClickButton : UIButton = { let button = UIButton() …
guarinex
  • 110
  • 1
  • 10
2
votes
0 answers

Swift3 - addTarget not working

class MyClass { let customView: MyView init() { customView = MyView() customView.checkBox.addTarget(self, action: #selector(checkBoxValueChanged(_:)), for: .valueChanged) } @objc func checkBoxValueChanged(_…
Louis
  • 406
  • 6
  • 13
2
votes
1 answer

Swift 3: Unrecognized selector sent to instance

I have a button in my view class attempting to add a selector function from a separate class as follows: class ProfileView: UIView { createAccountButton.addTarget(self, action: #selector(ProfileViewController.createAccountClicked), for:…
Brandon Lee
  • 194
  • 2
  • 12
2
votes
1 answer

Array of buttons Swift 3

if function "Savedata" is called, I add new button into [UIbutton] and I add new element into array [[Double]]. I want, for every button on index [i] to display data in array [[Double]] on index [i]. How shall I do the loop? @IBAction func…
Toby V.
  • 425
  • 1
  • 6
  • 15
2
votes
1 answer

Swift Enum to Cocoa Touch UIButton selector string

I was adding a target to a UIButton for my letterTapped() function like this: button.addTarget(self, action: "letterTapped:", forControlEvents: .TouchUpInside) I like how .TouchUpInside works with autocompletion and it looks neater and seems safer…
OsakaStarbux
  • 147
  • 12
1
vote
1 answer

Is there a way to programmatically associate a variable and a target object with the control in swift?

I'm creating a slider programmatically due to and Xcode bug, (don't let me center the thumb when I change the slider values, so I decided to do it using code) and I want to have a variable which saves the slider value. Is there a way to associate…
1
vote
1 answer

Button add target function not called in CollectionView cell

I have a collection view where each of the cells has a delete button. I added the following code to cellForItemAt indexPath function. let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellTwo", for: indexPath) as!…
1
vote
1 answer

Trouble adding a new "Send Event" to a set of UITextFields

Errors I'm getting:- I have 81 UITextFields that I want to add another Send Event too. Currently, they are all set to trigger one function for "Did End on Exit" but I want to add "Editing Changed" to all of them in order to call the same function.…
1
vote
2 answers

Buttons in collectionViewCell not triggering functions

I created a button in a supplementary collectionView cell as header and added a button with a target to it but it doesn't trigger the function when tapped. What am I doing wrong? Below is the button I created and its target function in the cell…
1
vote
3 answers

Swift class with uibutton.addTarget to UIView not working

I created a new file with the following class: import Foundation import UIKit var Feld = classFeld() class classFeld { let button = UIButton() func createButton() -> UIButton { button.frame = CGRect(x: 10, y: 50, width: 200,…
Andy
  • 185
  • 1
  • 13
1
vote
1 answer

Swift: how to add params in button.addTarget

I have a func below, but can`t send href for func. func someFunc() { linkBtn.addTarget(self, action: #selector(headerClick(_:href:)), for: .touchUpInside) return headerView } @objc func headerClick(_ sender: AnyObject, href: String) { …
ctwyw
  • 51
  • 5
1
vote
1 answer

How can I override addTarget in a UITextField for only UIControlEvent.allEditingEvents?

How can I override the addTarget function inside the UITextField class, but only for UIControlEvent.allEditingEvents? The function is like this, however I am not sure how to apply it only for a specific control event. override func addTarget(_…
dre_84w934
  • 678
  • 8
  • 27
1
vote
2 answers

Call UIButton AddTarget in the same class

I have a simple view V and view controller C. The controller calls a separate class X that build a webview and a button to close the webview. I instantiate class X (with a reference to view V) then call a method to attach both items (webview and…
Sucrenoir
  • 2,994
  • 1
  • 27
  • 31
1
vote
1 answer

Custom UIView: UIButton addTarget not called

My problem is that I have a custom UIView, which is representing a popup. Inside this view I want to have a slider, which has a label that gets updated every time I drag the slider around. The slider logic works, at least when I'm using it in a…
1
vote
1 answer

UITapGestureRecogniser add target not working

i have a objc function: @objc private func segmentedControlViewTapped(gestureRecognizer: UITapGestureRecognizer) I am trying to add this as a target for a gestureRecognizer but the code keeps crashing when i tap the segment control. let…
user2512523
  • 1,229
  • 2
  • 15
  • 25