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
1
vote
1 answer

Set target/action of a UITableViewCell subview inside the UITableViewController, without a storyboard

With a storyboard, you can easily customise a cell, with subviews, and insert actions of those subviews, directly inside the table controller, via - (IBAction)handle:(id)sender;But is it possible to do something similar, without a storyboard or a…
1
vote
0 answers

remove "one" action from multi actions in target-action UIbutton

[_btt1 addTarget:self action:@selector(clicked:) forControlEvents:UIControlEventTouchUpInside]; [_btt1 addTarget:self action:@selector(clicked2:) forControlEvents:UIControlEventTouchUpInside]; There are 2 actions in _btt1. 2013-05-31 10:33:31.300…
BluePrajna
  • 31
  • 2
1
vote
1 answer

Target-action vs Cocoa bindings

I am reading "What are Cocoa Bindings" in Apple's documentation. Note that this implementation does not use the target-action pattern. The slider does not send an action message to the controller. Instead, as the slider moves, it informs the…
Rounak
  • 613
  • 3
  • 8
  • 22
1
vote
1 answer

Can I implement a custom target-action in a NSView subclass?

I currently have a custom view class which is drawing a 2d game board representation on a window. When the user clicks on the board I am using the mouseDown: event to calculate the cell co-ordinates from the mouse position (I am doing this within…
1
vote
3 answers

Different results of two addTarget:action:forControlEvent: calls

The code is nothing more than a target-action for a button: [subButton addTarget:self action:@selector(pickerviewSubButtonClicked:) forControlEvents:UIControlEventTouchUpInside]; //[subButton addTarget:self…
tomjpsun
  • 436
  • 5
  • 12
0
votes
2 answers

Button's action causes "invalid selector" crash -- why?

This code results in an "invalid selector" error when the button I create is pressed. Where is the test function fetched from? Main.m mainScreen = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)]; [self.view…
Ray Y
  • 1,261
  • 3
  • 16
  • 24
0
votes
2 answers

Add selectors to multiple segmented controls in NIB file

I have two UIbuttons, and I want to assign the two buttons to a UITextView so that when one of the buttons is pressed, the text view content changes from what it had when previous button was pressed. I want to do this using a segmented control. How…
raptor85
  • 125
  • 2
  • 4
  • 12
0
votes
1 answer

NSURLRequest and target-action

As a novice iOS developer, I am trying to understand some concepts related to the callback mechanisms in iOS. My model makes HTTP requests through NSURLRequest to a backend rest service. The model has several methods which corresponds to the methods…
user928437
  • 141
  • 1
  • 2
  • 4
0
votes
2 answers

Is there any benefit of having (id)sender in IBAction

When coding with cocoa I've noticed that it's not necessary to have sender parameter when defining IBAction, hence following action: - (IBAction)showUserInfo:(id)sender; can be declared as - (IBAction)showUserInfo; So I'm wondering if there is any…
Eimantas
  • 48,927
  • 17
  • 132
  • 168
0
votes
2 answers

Mouse events handlers

MyNSImageView is a subclass of NSImageView, here I have: @interface MyNSImageView : NSImageView { } @end @implementation MyNSImageView //- (void) mouseDown: (NSEvent *) theEvent //{ // do not wish to implement mouseDown event handler from…
user523234
  • 14,323
  • 10
  • 62
  • 102
0
votes
1 answer

Swift UITextField target-actions as closure, problem with not removing target-actions

I have such code a little modified from code of Eric Armstrong Adding a closure as target to a UIButton But there is the problem with both codes. Those from Eric does remove all target-actions on func removeTarget(for controlEvent: UIControl.Event…
Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143
0
votes
1 answer

Target-Action parameter issue in Swift

I am following an iOS dev tutorial and reading their code. First Code: override func viewDidLoad() { super.viewDidLoad() let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(hideKeyboard)) …
Nan
  • 496
  • 3
  • 21
0
votes
2 answers

Why adding barBarttonItem won’t work if created out of scope where it’s added?

I ran into some problems when adding barButtons and found the solution in the answer to another question, but the it didn’t explain why you must create and add the buttons in the same scope. I want to know why you can’t create the buttons in class…
Antonia Zhang
  • 103
  • 11
0
votes
0 answers

More efficient way to add multiple Target-Actions on a UIControl

My app has numerous buttons whose behavior depends on the events they generate: .touchDown, .touchUpInside, .touchUpOutside, etc. I use the typical Target-Action mechanism to set these behaviors: class MyViewController: UIViewController { let…
MH175
  • 2,234
  • 1
  • 19
  • 35
0
votes
1 answer

NSButton not callable after CATransform3DMakeTranslation

I have a strange issue never seen on iOS but present on macOS Swift development. I have a NSButton which is added with an addSubview method to a custom NSView. The button has a target function. It is impossible to click on this button when it's…
Silvering
  • 756
  • 1
  • 6
  • 33