Questions tagged [addtarget]

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

92 questions
1
vote
2 answers

Swift 2.3 Button to open URL failing with error unrecognised selector

I have created a button to open url links and am failing with an unrecognised selector error. I would normally set the add target to be self just through how i have read online, but for this particular instance i get the error: cannot convert value…
Darren
  • 231
  • 1
  • 2
  • 7
1
vote
3 answers

How to pass two arguments to a UIButtons target method in iOS?

In my code I've to pass two arguments to targetMethod printMethod, I can pass the button.tag as one argument and how to pass the other argument? Please Give an Example. My code: button.tag = indexPath.row; secondArgument = indexPath.section; …
AMI amitekh
  • 198
  • 3
  • 16
1
vote
2 answers

Swift - UISwitch not updating when toggled On/Off

I am trying to create a UISwitch programatically (No IBOutlets or IBActions) and I can't seem to figure out how to get the switch to change states when pressed. I thought that ... mySwitch.addTarget() ... would be called every time the switch was…
sMk
  • 65
  • 1
  • 8
1
vote
2 answers

swift: Adding an action to an array of buttons

I'm designing a simple Sudoku app and need to trigger an action when any one of the 81 buttons are clicked. I created an array of UIButtons in my ViewController: class SudokuBoardController : UIViewController { @IBOutlet var collectionOfButtons:…
colinmcp
  • 446
  • 2
  • 5
  • 19
1
vote
0 answers

Swift iOS programming access a button inside a view programmatically

I'm new to iOS programming. I'm developing a custom keyboard with a custom nib file for it's view. How can I add target for buttons in the nib file without connect them manually to my UIInputViewController? I tried this code but doesn't works! class…
Mansour
  • 445
  • 1
  • 4
  • 14
1
vote
3 answers

How do I update textfield2 based on editing textfield1?

I like to update textfield2 as soon as totalAmount has been edited, I am trying the following: totalAmount.addTarget(self, action: "changeTextField2:", forControlEvents: UIControlEvents.EditingDidEndOnExit) func changeTextField2(textField:…
alex
  • 4,804
  • 14
  • 51
  • 86
1
vote
1 answer

Is addTarget safe to use?

I'm a bit skeptical recently, with the use of addTarget() to UITableViewCell in cellForRowAtIndexPath. I'm also eager to know what is the best practice to listen button event from UITableViewCell. My confusion begins when I see I've no way to…
Santanu Karar
  • 1,034
  • 1
  • 12
  • 27
1
vote
1 answer

Call method in UIViewController to target error

in my MainMainViewController I created new UIView (ContentView). I set DetailViewController *detailView = [[DetailViewController alloc] initWithObject:paAnnotation]; detailView.view.frame = CGRectMake(0, 0, …
Patrik Dendis
  • 313
  • 6
  • 20
1
vote
1 answer

How to subclass an UIButton to pass multiple NSString parameters via addTarget:action:forControlEvents

I have to programmatically define (without using any IBAction) a UIButton that when tapped gets the values of 3 NSString parameters and executes a Segue. The method used for executing the Segue is called via: [myButton addTarget:self…
Stefano
  • 33
  • 1
  • 7
1
vote
2 answers

Swift: Are addTarget actions only allowing class methods?

I tried to add a target to a UIButton and stumbled upon a weird behaviour if i try: //h = a collection view header switch myVar { case "none": h.button.addTarget(self, action: "buttonTapped:", forControlEvents: .TouchUpInside) func…
longbow
  • 1,593
  • 1
  • 16
  • 39
0
votes
1 answer

Add Target for a button doesn't work for another UIView

I implemented header(UIView) for my view controller but i cannot add target for the button inside at the UIView. I believe this is very understandable for everyone but i can add more detail if you want MY View Controller Code inside loadView() let…
0
votes
0 answers

Swift//How can I add an action to a button inside a custom view class, where the action need to access a tableView Cell property?

I made a custom UIView class, it has a viwe and inside that view there is a button. The problem is implement the action for the button, the action that i need is when press that button a label textcolor inside a table view cell should changed to…
0
votes
1 answer

How to pass parameter in button's addtarget

I have a bottom sheet, and on that sheet there is a button. I want that when i tap to that button it go to the page it is related to. So, i connected that from storyboard to code @IBOutlet weak var openPage: SheetOpenPageButton! And wrote extension…
0
votes
1 answer

Unexpectedly found nil of optional value when addtarget of button

There is an error in addTarget of buttonSandK I Check the reference outlet and it's connected+ if i remove addtarget, the code run. What am i missing here public protocol tenorFooterDelegate: AnyObject{ func tapSK(message : String) } class…
Loka
  • 41
  • 5
0
votes
1 answer

How to add target to UITextField in a class other than ViewController

I am trying to write a class that has a method which observe text changes on UITextField objects. When in ViewController, code below works as intended: class ViewController: UIViewController { @IBOutlet weak var password: UITextField! …
Neco
  • 55
  • 1
  • 1
  • 5