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
2
votes
1 answer

implementing Target - Action pattern in custom view

I've created a custom view which inherits from NSView. My goal is to notify my NSWindowControl which is associated with the window that contains the custom view, when the user click the the custom view. I would like to implement this using the…
omiez
  • 119
  • 1
  • 9
2
votes
2 answers

UITextField Target/Action vs Delegate Methods

I used to use XCode the develop my apps and using that; I could create a link up in IB/Storyboard that synthesized this methods: - (void)addTarget:(id)target action:(SEL)action forControlEvents: (UIControlEvents)controlEvents for when However, no…
pachun
  • 926
  • 2
  • 10
  • 26
1
vote
3 answers

Programmatically create UIButton - won't call action?

I have a custom class, and that class has a UIButton instance variable. I have added this code in the class designated initializer: theFishDeathView = [UIButton buttonWithType:UIButtonTypeCustom]; [theFishDeathView setFrame:CGRectMake(15, 15, 50,…
Seerex
  • 591
  • 1
  • 9
  • 21
1
vote
2 answers

How do I define an action for a custom NSControl in code?

I have made a subclass of NSControl which is a combination of a number formatted NSTextField and an NSStepper. Here is the basic code: class StepperWithNumberField: NSControl, NSTextFieldDelegate { let numberField: NSTextField let stepper:…
MassMover
  • 529
  • 2
  • 17
1
vote
2 answers

Handling target/action weak reference with NSOperation

I'm using a NSOperation to handle background processing in an iOS app, and I'm trying to understand the target/action pattern. In the delegate pattern, the delegate is held as a weak reference, and the delegate object is responsible for setting the…
jrdioko
  • 32,230
  • 28
  • 81
  • 120
1
vote
1 answer

How do I set primaryActionTriggered for a custom UIControl?

I've created a custom UIControl. The closest comparison is a UIStepper but it is a subclass of UIControl because its wholly custom. For most UIControls you can create target actions with primaryActionTriggered to avoid needing to know which action…
Ryan Poolos
  • 18,421
  • 4
  • 65
  • 98
1
vote
2 answers

Target Action for lazy Button does not work

Using Swift 5.1.3, iOS13.3, XCode11.3, I try to create a simple Button Target Action. However, the Button is inside its own StackView class and moreover, is a lazy button. Why is the Target Action not working in my Code ? i.e. callButtonMethod is…
iKK
  • 6,394
  • 10
  • 58
  • 131
1
vote
1 answer

Member reference base type 'Class' is not a structure or union - has the Fixit led me in the right direction?

I’m trying to make a delegate that will send messages from UIButtons within a custom UIView called SGView and am a bit out of my depth following the error messages. I recently learned how to get a delegate to send messages successfully from within…
Greg
  • 1,750
  • 2
  • 29
  • 56
1
vote
1 answer

Prevent parent UIControl from responding to touchDown events

I am creating a reusable MetaControl that consists of a few sub-controls (see pic). It inherits from UIControl, and contains 2 simple UIButtons and a custom slider I created. The CustomSlider also inherits from UIControl. In the MetaControl's…
MH175
  • 2,234
  • 1
  • 19
  • 35
1
vote
3 answers

How do I find the action function for a target in iOS

I hope I can make this clear. I have button and I want to know what function in what object is the target for it's .touchDown event. There are properties and functions in iOS that might be what I'm looking for, but I can't make them work. The…
S'rCat
  • 468
  • 1
  • 4
  • 16
1
vote
1 answer

How to place variables inside button target selector

I have a button that I add a target to, the selector contain a variable. Can I add the variable into the selector without receiving an error? Thank you in advance. //this cause a selector error when run self.save.addTarget(self, action:…
SwiftER
  • 1,235
  • 4
  • 17
  • 40
1
vote
1 answer

Programmatically added buttons target action not working in custom tableviewcell

I added programmatically two buttons in custom tableviewcell, but target action not working. What can i do to solve this problem ?(swift) This is my code of adding buttons: override func awakeFromNib() { super.awakeFromNib() func…
Alexandr
  • 27
  • 5
1
vote
2 answers

Setting C function as selector for NSButton produces no results

I have a function which creates an instance of button, and I'd like the callback to go to a separate function. This doesn't work (no error or anything, just nothing happens when I click on the button). I need it to be a C function because I'm…
lucasem
  • 481
  • 3
  • 12
1
vote
1 answer

How to reference a subview from another in the view hierarchy programmatically?

I have a (simplified) Cocoa view hierarchy as follows: window - contentView -- view1 ---> button1 --view2 ---> textField1 Importantly, the button1 & textField1 do NOT share an immediate superView. I would like to add a target-action to button1 to…
Sam
  • 2,745
  • 3
  • 20
  • 42
1
vote
0 answers

iOS bar button item and text field delegate method order

I have a viewController that is presented modally, and when the cancel leftBarButtonItem is pressed I want a certain property to be set to nil before the UITextFieldDelegate method textFieldShouldEndEditing gets called. I was able to do this when I…
funct7
  • 3,407
  • 2
  • 27
  • 33