@selector and another class (Objective-C)

Inside the object, I use NSMenu addItemWithTitle:action:keyEquivalent:to create NSMenuItems. The problem is that I want to call a method on another object as an action. The part action:takes an @selectoras parameter , and I don't know how to use this to call methods on other objects. I could create a method inside the object creating NSMenu, and then from this object I could call a method that I would like to call on another object. But then I do not know any good naming rules for this.

+3
source share
1 answer

Use setTarget:for the newly created object NSMenuItemto set the target for the action message. Here's an example from the ObjectVive-C programming language: Selectors , which does a similar thing for a table cell:

[myButtonCell setAction:@selector(reapTheWind:)];  
[myButtonCell setTarget:anObject];  
+2
source

Source: https://habr.com/ru/post/1753758/


All Articles