addTarget method is used to assign actions to UIControl elements in IOS.
Questions tagged [addtarget]
92 questions
0
votes
1 answer
delegate returns nil even after set to self
I have a ViewController that has a CollectionView of two cells. One of the cells (LoginView) has the login buttons, which I want the ViewController to handle.
The error I'm getting is an unexpected nil even though delegate is set to self in…

Qoarth
- 1
- 1
- 2
0
votes
2 answers
Swift4 addTarget at UIButton doesnt work in UIView
I programmatically created an UIButton and added it to a subview. AddTarget doesnt work there though. AddTarget only works if I add the button to the mainview.
self.view.addSubview(button)
instead of
ViewSystem.addSubview(button)
Doesnt anyone…

Andy
- 185
- 1
- 13
0
votes
1 answer
Cannot add target with parameters in CollectionViewCell's button (Swift 4)
There is a button in my CollectionViewCell, I would like to trigger the UIActivityViewController (with an URL passing) when the button tapped.
I'm trying to add a target (with parameter) to the button which is in CollectionViewCell, but it seems it…

Vincent
- 486
- 6
- 20
0
votes
2 answers
Adding multiple UIButtons to an UIView with a selector action
I've added some buttons to an UIView (via addSubview) programmatically. I’ve added to this button an @selector with a function. However, they appear in the view but when I do click, the last button works only.
Into my .h:
@property (nonatomic,…

user3745888
- 6,143
- 15
- 48
- 97
0
votes
1 answer
Calling a custom UIButton function in didSelectRowAtIndexPath
Can anyone tell me how to call a custom function created for a UIButton clicked inside a cell in a didSelectRowAtIndexPath. I have a shopping cart button in a tableViewCell, when clicked I am changing the icon and maintaining a shopping cart list…

Adeel Ilyas
- 81
- 1
- 9
0
votes
2 answers
Add target for button in table view cells
I have a table view that its cells have a button in themselves and these buttons should open a view with an unique id. So I need to passing an argument to my buttons but with addTarget property I just can call function without any…

p.yarandi
- 59
- 1
- 11
0
votes
2 answers
Assign 'action' dynamically in uibutton.addTarget
please bear with me, as I'm new to swift -4 weeks old-.
I've created the following 2 functions in fileA.swift
func custombttn(theSelector:Selector)-> UIButton{
let bttn = UIButton(frame: CGRect(x:20, y:400, width:200, height:30))
…

Gamal Elsayed
- 63
- 2
- 10
0
votes
2 answers
Delegate method or Global declaration to add action for UIButton?
In my custom view I’ve created one button. To add action for that button which is feasible solution Creating Delegate method or Declaring UIButton as global variable and addTaget. Suggest me please.

Karthikeyan Bose
- 1,244
- 3
- 17
- 26
0
votes
1 answer
How to change size of PaintCode produced object
I am a newbie, trying hard to make my first app. I would like to change the size of a (bezierpath) object(?) made by PaintCode by receiving a value from a UISlider. Can anyone help me what is wrong with my code below and how to make it work?
int…

Lee
- 41
- 1
- 8
0
votes
0 answers
addTarget for Multiple Buttons Issue
for (index,phoneNum) in temp_arr_phoneNum.enumerated()
{
if temp_arr_msgType[index] == "3"
{
let btnimage : UIButton = UIButton()
…

Socraties Srikanth
- 21
- 1
- 5
0
votes
1 answer
Swift 3 - button in .xib custom tableviewcell is not performing action
I have a tableviewcontroller, where i have created custom tableviewcell in a .xib files.
The button (myButton) is used on myCustomTableViewCell.xib has an outlet to myCustomTableViewCell.swift
I have set an action for the button in the…

Dave
- 167
- 17
0
votes
1 answer
Segmented control addTarget() crashing app below iOS 9.0
My app has been released recently but it supports iOS 8.2.
Unfortunately, below iOS 9.0 tapping a segmented control which has been added programmatically crashes the app with no error message in the console.
I believe that the line where the target…

nontomatic
- 2,003
- 2
- 24
- 38
0
votes
2 answers
Re-use animation throughout iOS views
Not sure if my thinking here is correct but I have similar animations I use throughout my iOS project and I would like to condense it to 1 file and reuse wherever I want.
A brief example. In my animations file I have a scale…

user934902
- 1,184
- 3
- 15
- 33
0
votes
1 answer
Error when adding selector to addTarget function for UIStepper - Swift 3
I am trying to incorporate a UIStepper into a UITextField, while incrementing the value of the stepper, the UITextField updates with it to that value. I keep getting the error:
"Terminating app due to uncaught exception…

Gar
- 901
- 1
- 7
- 9
0
votes
1 answer
Custom Button Not Working in Swift
I have a UIViewController, a Custum UIView, and a GameController. The CustumUiView is layered on top of the UIViewController and I need to seperate out the views to track clicks on the UIView. I have a custom button in the Custum UIView "Interface…

Apocal
- 162
- 11