objective c - Passing a Variable through NSStatusItem's Action -


i need add multiple status menuitems programmatically. have never used nsstatusitem before. following have.

- (void)showstatus {     (nsinteger i4 = 0; i4 < alertarray4.count; i4++) {         nsstring *person = [[alertarray4 objectatindex:i4] objectforkey:key4e];         nsstring *imagepath = [[alertarray4 objectatindex:i4] objectforkey:key4f];         nsstring *nextdob = [[alertarray4 objectatindex:i4] objectforkey:key4h];         nsimage *personimage;             if ([imagepath isequaltostring:@"0"]) {                 personimage = [self imageresize:[nsimage imagenamed:@"usernone"] newsize:nsmakesize(16.0f,16.0f)];             }             else {                 personimage = [self imageresize:[nsimage imagenamed:@"userone"] newsize:nsmakesize(16.0f,16.0f)];             }                nsstring *menutitle = [nsstring stringwithformat:@"%@ in %@ days",person,nextdob];             nsmenuitem *menuitem = [[nsmenuitem alloc] initwithtitle:menutitle action:@selector(statusitemclicked:) keyequivalent:@""];             [menuitem setimage:personimage];         }     statusitem = [[nsstatusbar systemstatusbar] statusitemwithlength:nsvariablestatusitemlength];     statusimage = [nsimage imagenamed:@"appicon16"];     [statusitem setimage:statusimage];     [statusitem setmenu:statusmenu];     [statusitem settitle:alertcount.stringvalue]; }  - (void)statusitemclicked:(nsstring *)num {     nslog(@"hello"); } 

and application posts status menu number of items = i4. don't understand how pass variable statusitemclicked application know menuitem user has selected. how can send variable (i4) statusitemclicked? if use performselectorinbackground, can append variable withobject. guess can't in case.

thank help.

i don't know how works. anyway, i've ended following, serves me satisfaction.

- (void)showstatus { (nsinteger i4 = 0; i4 < alertarray4.count; i4++) {     ...     nsstring *num4 = [nsstring stringwithformat:@"%li",(long)i4];     nsstring *menutitle = [nsstring stringwithformat:@"%@ in %@ days",person,nextdob];     nsmenuitem *menuitem = [[nsmenuitem alloc] initwithtitle:menutitle action:@selector(statusitemclicked:) keyequivalent:@""];     [menuitem settarget:self];     [menuitem setrepresentedobject:num4]; } statusitem = [[nsstatusbar systemstatusbar] statusitemwithlength:nsvariablestatusitemlength]; statusimage = [nsimage imagenamed:@"appicon16"]; [statusitem setimage:statusimage]; [statusitem setmenu:statusmenu]; [statusitem settitle:alertcount.stringvalue]; }  - (void)statusitemclicked:(id)sender {     id selecteditem = [sender representedobject];     nslog(@"%@",selecteditem); } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -