objective c - How can I manage a new NSMenuItem? -



objective c - How can I manage a new NSMenuItem? -

i'm adding menuitems code.

i'm using "selector" problem because have "mutable" menu dont know how many rows have, need manage each 1 not knowing how many are.

perhaps code can explain improve problem.

i have loop follow (more or less)

for (punterolineas=punterolineas; punterolineas <= intnumlineas; punterolineas++) { nsdictionary *dic = [lineas objectatindex:punterolineas]; nsmenuitem *item = [[nsmenuitem alloc] initwithtitle:[dic objectforkey:@"txtmostrado"]action:@selector(menuitem:) keyequivalent:@""];//where menuitem manage item, need identify 1 is. [item settarget:self]; [statusmenu additem:item]; }

i think reply "sender" of "menuitem" ibaction, how can manage it?

thanks in advance

there several approaches:

set tag of each menu item. in action method (-menuitem:), check sender's tag , decide do. in case, might utilize punterolineas, assuming lineas array remain same lifetime of menu items.

set representedobject of each menu item. in action method, obtain representedobject of sender , utilize command do. in case, might utilize dic representedobject if has info command menu ought do.

use proper model object — instance of custom class — instead of nsdictionary represent lines. have menu item target model object instead of self. utilize method of model class rather method of class containing above code action method. again, requires line objects live @ to the lowest degree long menu items.

objective-c xcode osx cocoa

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -