objective c - How to use predicate on arrayController and Core Data -
objective c - How to use predicate on arrayController and Core Data -
i have nsoutlineview shows info core info store. info presented using nsarraycontroller linked managedobjectcontext , displayed in nsoutlineview using nstreecontroller (much described here). filter info shown using nspredicate (or else) can't work. note osx , not ios can't utilize nsfetchedresultscontroller.
i able retrieve right info , store these in nsarray. however, enabling automatic update of see in outlineview using filtered info not work. have:
[arraycontroller setmanagedobjectcontext:_coredatahelper.context]; nsfetchrequest *request = [[nsfetchrequest alloc] init]; nsentitydescription *entity = [nsentitydescription entityforname:@"sdrdfileobject" inmanagedobjectcontext:_coredatahelper.context]; [request setentity:entity]; nsnumber *directionlimit = @1; nspredicate *predicate = [nspredicate predicatewithformat:@"direction = %@", directionlimit]; [request setpredicate:predicate]; nserror *error; [arraycontroller setcontent:[_coredatahelper.context executefetchrequest:request error:&error]]; [_coredatahelper.context reset]; [arraycontroller fetch:self]; [outlineview reloaddata];
as can see question close one, still struggling. if work using setcontent arraycontroller assume run problem having mismatch between core info context , content of arraycontroller. suggestions or illustration how correctly appreciated.
suggestion 1: seek ditching array controller.
i'm not exclusively sure objective of author of first link direct is, he/she that, @ to the lowest degree in mutual nsoutlineview
setup, little odd. controller object required extract values core info , display them in outline view nstreecontroller
. tutorial on other hand suggests interposing array controller: "in nib file you’ll need array controller bound nsmanagedobjectcontext, set entity mode, , fetch predicate of parent == nil. fetch our top level objects – entities without parent." sentiment should doing tree controller not array controller. lean in mind think first thing should you're info appearing correctly tree controller, 1 time you've achieved this, can start think filtering outline view.
suggestion 2: filtering
unlike nsarraycontroller
, nstreecontroller
objects have no filterpredicate
in class reference. i'm not sure why is, outline view have implement filtering behaviour yourself. can bit tricky, it's not difficult. instance, in 1 of projects, have big drag-and-drop compatible tree controller/outline view setup apes way xcode filters files when type search bar positioned in bottom left-hand corner. did adding category nstreecontroller
called -filtercontentusingpredicate
returns array. 1 time filtering complete, utilize phone call [-nstreecontroller setcontent:
] update contents of outline view reflect filter.
objective-c cocoa core-data nspredicate nsarraycontroller
Comments
Post a Comment