cocoa - How to configure content for NSPopUpButton -


i have nspopupbutton configured bindings , coredata. working perfectly, add item implements action "edit list", like

item 1 item 2 item 3 item 4 ------ edit list.. 

is possible bindings?

i think answer no, @ least not completely. thought provide content button programatically , maintain bindings selected value , came with

- (void)updatesectorpopupitems {     nsfetchrequest *request = [[nsfetchrequest alloc] initwithentityname:@"sector"];     nssortdescriptor *sortposition = [[nssortdescriptor alloc] initwithkey:@"position" ascending:yes];      [request setsortdescriptors:@[sortposition]];      nserror *anyerror = nil;     nsarray *fetchobjects = [_gdcmanagedobjectcontext executefetchrequest:request                                                                     error:&anyerror];     if (fetchobjects == nil) {         dlog(@"error:%@", [anyerror localizeddescription]);     }      nsmutablearray *sectornames = [nsmutablearray array];     (nsmanagedobject *sector in fetchobjects) {         [sectornames addobject:[sector valueforkey:@"sectorcatagory"]];     }      [_sectorpopupbotton additemswithtitles:sectornames];     nsinteger items = [[_sectorpopupbotton menu] numberofitems];      if (![[_sectorpopupbotton menu] itemwithtag:1] ) {         nsmenuitem *editlist = [[nsmenuitem alloc] initwithtitle:@"edit list..." action:@selector(showsectorwindow:) keyequivalent:@""];         [editlist settarget:self];         [editlist settag:1];         [[_sectorpopupbotton menu] insertitem:editlist atindex:items]; } 

a couple of problems i'm having this

1) when adding menu item using

[_sectorpopupbotton menu] insertitem:editlist atindex:items];  

no matter value entered in atindex, item appears @ top of menu list.

2) want "edit list..." menuitem initiate action, how prevent being selected value?

you might using nsmenudelegate method.

actually in way can keep bindings getting nspopupbutton content objects (in case nsarraycontroller bound coredata stack).

1) set object delegate nspopupbutton internal menu, can in interface builder drilling down nspopupbutton reveal internal menu. select , set delegate in connections inspector panel object have designated task. such delegate might example provide same viewcontroller object manages view nspopupbutton exists. you'll need have object provided delegate adhere nsmenudelegate informal protocol.

2) implement nsmenudelegate method menuneedsupdate: there you'll add nsmenuitem(s) (and separators) want provide in addition fetched nspopbutton's bindings. example code be:

#pragma mark nsmenudelegate - (void)menuneedsupdate:(nsmenu *)menu {     if ([_thepopupbutton menu] == menu && ![[menu itemarray] containsobject:_editmenuitem]) {         [menu additem:[nsmenuitem separatoritem]];         [menu additem:_editmenuitem];     } } 

in example _editmenuitem nsmenuitem property provided object implementing nsmenudelegate method. this:

_editmenuitem = [[nsmenuitem alloc] initwithtitle:@"edit…" action:@selector(openeditpopupmenuvc:) keyequivalent:@""]; // set target action: selector implemented. _editmenuitem.target = self; 

you'll implement method openeditpopupmenuvc: present user view responsible editing content of popupbutton (in case coredata objects provided via bindings).

the problem haven't yet solved approach when getting view edit happens, nspopupbutton have new item "edit…" selected, rather "valid" one, inconvenient.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -