Questions tagged [target-action]

Target-action is a design pattern from Apple in which an object holds the information necessary to send a message to another object when an event occurs.

The Target-action design pattern is implemented in UIControl () in iOS / UIKit and NSControl () in macOS / AppKit.

Target Action Design Pattern

66 questions
34
votes
1 answer

How can I send a "UIControlEventValueChanged" event from my custom control?

I've created a custom picker view type of control by subclassing UIView. I would like to be able to send a "UIControlEventValueChanged" control event from within this control, so that I can register for it in whichever view controller is using the…
Christian Gossain
  • 5,942
  • 12
  • 53
  • 85
18
votes
1 answer

Disable action - user taps on tabbar item to go to root view controller

I want to disable the default action when user taps the tabbar item. For example, i have a tabbar with Tab1, Tab2 and Tab3. In Tab1, user can navigate from View1 to View3 (View1 > View2 > View3). If user is at View3, and he taps the Tab1, the…
Mustafa
  • 20,504
  • 42
  • 146
  • 209
12
votes
1 answer

How do I set the sender on a NSMenuItem's action?

The Apple documentation says that the sender passed to the NSMenuItem's action can be set to some custom object, but I can't seem to figure out how to do this. Is there a method I'm not seeing someplace in the documentation?
Jeff Barger
  • 1,241
  • 1
  • 13
  • 19
9
votes
1 answer

UIControl: call-order when adding multiple target-action pairs to the same event?

If I add to a control multiple target-action pairs for the same event, will the control send the action messages to the targets in the same order that I added them? I read the following References but couldn't find an answer. -…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
7
votes
1 answer

Any differences between @objc and IBAction when programmatically creating UIButton event?

When creating an eventhandler from a UIButton from the Storyboard, Swift adds @IBAction before func. When adding an event programmatically to a UIButton to a func, Swift gives a error and says I need to add @objc in front of my method, but when I…
J. Doe
  • 12,159
  • 9
  • 60
  • 114
4
votes
1 answer

RemoveTarget from UITapGestureRecognizer

I've added an action as anonymous method to my gesture recognizer UITapGestureRecognizer tapGesture = new UITapGestureRecognizer (); tapGesture.AddTarget (() => HandleTap (tapGesture)); How can I remove the target? UIGestureRecognizer.Token is…
testing
  • 19,681
  • 50
  • 236
  • 417
3
votes
2 answers

Swift: Protocol method as Action in target-action

I'd like to have a protocol: protocol CameraButtonDelegate: class { func cameraButtonDidPress(_ sender: UIButton) } So, I could assign any client to a button, e.g.: cameraButton.addTarget(delegate, action: #selector(cameraButtonDidPress), for:…
Richard Topchii
  • 7,075
  • 8
  • 48
  • 115
3
votes
0 answers

How to add a custom Sent Action for a custom NSControl (NSView, NSButton) in Swift

I want to define a custom NSControl (or NSView), now the problem is how to add a Sent Action to it. As shown in the image, here are one or more Sent Actions for a control in the Connections inspector, for a NSButton, here's only one action, for a…
Mandroid
  • 225
  • 1
  • 10
3
votes
1 answer

UISlider's Value Changed target is NOT called

I have a UISlider in the XIB file with an IBAction outlet hooked up to its corresponding view controller. Everything looks fine (see image below). However, when I actually move the slider in the simulator - the Value Changed (sliderValueChanged in…
etayluz
  • 15,920
  • 23
  • 106
  • 151
3
votes
3 answers

How to add event to UICollectionView cells?

I want to handle tapping UICollectionView cells. Tried to achieve this by using the following code: -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString…
Sergey
  • 47,222
  • 25
  • 87
  • 129
2
votes
2 answers

Xcode: How do I remove an action from a object?

I need to remove an action from a object and then add a new one. I've used this code to add the new action: [Button addTarget:self action:@selector(newAction:) forControlEvents:UIControlEventTouchUpInside]; I've then tried to use this code to…
Eksperiment626
  • 985
  • 3
  • 16
  • 30
2
votes
3 answers

How to add an action to a UIButton that is in another class

The code below compiles fine, but crashes with an unrecognized selector sent to instance error. I have one class that inherits from UIViewController: class Controller: UIViewController { override func viewDidLoad() { let toolbarWrapper =…
RPatel99
  • 7,448
  • 2
  • 37
  • 45
2
votes
1 answer

Why cannot I open the Preferences from each windows?

I have come across this Cocoa application (source code) that shows a main Window. As long as this window is key it is possible to open the Preferences window from the Main menu as well as by hitting Command-, but when the main window is not key and…
rano
  • 5,616
  • 4
  • 40
  • 66
2
votes
0 answers

Binding in Xcode 8 and Swift 3: Target never gets called and argument is passed as uninitialized

Here's 2 binding issues I'd like to share with you, related to selector name and parameters when configured in IB. I have CoreData objets retrieved through an ArrayController and populated in a NSTableView. All the binding is made through Interface…
Joshua
  • 147
  • 1
  • 12
2
votes
1 answer

NSFontPanel changeFont not called

I'm trying to use a font panel in my Cocoa app and I can't get the changeFont: method to be called. I had it working properly in another app and I just copied and pasted the code over but for some odd reason the changeFont method isn't called…
guitarflow
  • 2,930
  • 25
  • 38
1
2 3 4 5