Questions tagged [addtarget]

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

92 questions
0
votes
1 answer

Swift AVPlayerViewController add target on playing video

I am using AVPlayerViewController for playing video.The problem is that how can I detect the video is started to play? Usually is to addTarget but I cannot find any Target that I can add on that event. Can someone help me? Thanks in advance.
Janice Zhan
  • 571
  • 1
  • 5
  • 18
0
votes
1 answer

Offscreen UIButton action not triggered - iOS

I have two UIButton's created off screen that are animated onto the screen when a button is pressed. However, neither of the button's target functions are never called, as I believe the buttons are not being "pressed". The buttons do work if I…
Dando18
  • 622
  • 9
  • 22
0
votes
1 answer

addTarget not firing any event

I have the following code and the doneButton handler is never invoked. Any idea what might be going wrong? I have tried many different formats for the selector, also with and without parameters. I also made sure that the UIView received touch events…
Batiatto
  • 59
  • 6
0
votes
2 answers

Swift UIButton addTarget launch automattically

I have a little problem with my addTarget in UIButton. When I run my app, my function is automatically launched, while he is necessary to press the UIButton to launch. I don't know where is my problem. My Button let BTN_happy : UIButton =…
Kevin Py
  • 2,459
  • 2
  • 22
  • 33
0
votes
2 answers

EXC_BAD_ACCESS, When Calling Button Method From Another Class

I'm calling a method from my DrawMenuclass in my ViewControllerclass, which draws an oval (currently circle) button, pretty simple. It draws the button perfectly, but if I tap the button it crashes. This happens even though I have created an…
0
votes
1 answer

Unrecognized selector sent to instance tableview swift

In my cellFoRowAtIndexPath I want to add a function on a button that belongs to the cell. In my cellFoRowAtIndexPath I have added this code. cell.acceptBtn.addTarget(self, action: "acceptRequest", forControlEvents: .TouchUpInside) And then I have…
kareem
  • 903
  • 1
  • 14
  • 36
0
votes
1 answer

Button click crashes the whole application

I am currently building an application's UI without using IB or storyboard. I have the following hierarchy: 1. ViewController: which is the main view controller. 2. DrawerViewController: which is the view controller for the lower drawer menu. …
Omar Kanawati
  • 59
  • 3
  • 7
0
votes
0 answers

UIButton with action-selector method in different class

Related to this previous question (Creating UI elements programmatically in Objective-C), this method resides in one class of the project, and other classes are able to call it to programmatically create buttons: UIButton *createButton(CGFloat…
iSofia
  • 1,412
  • 2
  • 19
  • 36
0
votes
1 answer

iOS click on dynamic UIButton crashes

I'm creating programmatically a UIButton with an Image. UIButton * bericht = [[UIButton alloc] initWithFrame:CGRectMake(tableView.bounds.size.width- height, 0, height, height)]; [bericht setBackgroundImage:[UIImage imageNamed:@"bericht.png"]…
fsulser
  • 853
  • 2
  • 10
  • 34
0
votes
1 answer

How create buttonAction functions dynamically in Swift

In a MCQ app I create multiple UIButton programatically like this func createNewButton(buttonName: String, xPosition: CGFloat, yPosition: CGFloat) -> UIButton { let myButton = UIButton(frame: CGRectMake(0, 0, 50, 50)) myButton.center =…
magohamote
  • 1,484
  • 1
  • 17
  • 29
0
votes
2 answers

iOS : assign same selector to multiple buttons, which one is the best way?

Usually I'm assigning single selector to multiple UIButtons in this way only, [buttonOne addTarget:self action:@selector(someAction:) forControlEvents:UIControlEventTouchUpInside]; [buttonTwo addTarget:self action:@selector(someAction:)…
Hemang
  • 26,840
  • 19
  • 119
  • 186
-1
votes
1 answer

Why does the selector, @objc, function add a subview, of my button image (as a UIImageView), in my UIButton?

I first declare the button let balloon = UIButton() A background image then gets added to the balloon balloon.setBackgroundImage(UIImage(named:"balloon.jpg"), for: .normal) An image view of the points get added to the balloon as a subview subView…
Spencer
  • 11
  • 6
-1
votes
2 answers

addTarget adding extra events

I want to add another events when the button is clicked. i use addTarget to observe the button when is clicked and call a method name showModal. see the code below. headerView.addTaskButton.addTarget(self, action: #selector(showModal), for:…
Doyeon
  • 7
  • 7
-1
votes
1 answer

"addTarget" action function of UIButton not called (strikethrough)?

I have a UIButton within a UITableViewCell. When I call addTarget on the button and attempt to put a function in, the autocomplete has the function crossed out with a white line (see first image). Xcode still allows me to put the function in and run…
gmdev
  • 2,725
  • 2
  • 13
  • 28
-1
votes
2 answers

Swift: Target not getting called on a subclassed UIButton

CustomButton.swift class CustomButton: UIButton { override func draw(_ rect: CGRect) { //drawing code } } ViewController.swift let testCustom = CustomButton() testCustom.draw(CGRect(x: 0, y: 0, width: 0, height:…
RanLearns
  • 4,086
  • 5
  • 44
  • 81