Selecting an object of a NSArrayController

  • Hi,

    I have an NSArrayController which controles entities.
    These entities have a boolean attribute and there is
    exactly one entitie where this attribute is YES, all
    the others are NO. When I want to select the one entity
    with the attribute set to YES, I iterate through the
    NSArrayController's arrangedObjects and when I find
    the entity, I call setSelectionIndex to the index of
    the object within arrangedObjects.
    This works pretty good, but I wonder if there is a more
    convenient way to perform this, something like
    "selectObjectWithValueForKey". Is there a way to do
    this?

    Many thanks in advance,
    Michael
    --
    GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
    Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
  • Since there's only one entity that can be YES, you'd be faster and
    less memory-consuming if you just stored the index of the element that
    has YES, instead of storing YES/NO for every element and then having
    to find the right one.

    On Jan 4, 2008, at 2:32 PM, Michael Varlik wrote:

    > Hi,
    >
    > I have an NSArrayController which controles entities.
    > These entities have a boolean attribute and there is
    > exactly one entitie where this attribute is YES, all
    > the others are NO. When I want to select the one entity
    > with the attribute set to YES, I iterate through the
    > NSArrayController's arrangedObjects and when I find
    > the entity, I call setSelectionIndex to the index of
    > the object within arrangedObjects.
    > This works pretty good, but I wonder if there is a more
    > convenient way to perform this, something like
    > "selectObjectWithValueForKey". Is there a way to do
    > this?
    >
    > Many thanks in advance,
    > Michael
    > --
    > GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
    > Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
    >

    Hank Heijink
    <hank.list...>
  • One option would be to fetch objects matching your criteria (attribute
    == 1) and then [myArrayController setSelectedObjects:fetchResults];

    Wil

    On Jan 4, 2008, at 11:41 AM, Hank Heijink wrote:

    > Since there's only one entity that can be YES, you'd be faster and
    > less memory-consuming if you just stored the index of the element
    > that has YES, instead of storing YES/NO for every element and then
    > having to find the right one.
    >
    > On Jan 4, 2008, at 2:32 PM, Michael Varlik wrote:
    >
    >> Hi,
    >>
    >> I have an NSArrayController which controles entities.
    >> These entities have a boolean attribute and there is
    >> exactly one entitie where this attribute is YES, all
    >> the others are NO. When I want to select the one entity
    >> with the attribute set to YES, I iterate through the
    >> NSArrayController's arrangedObjects and when I find
    >> the entity, I call setSelectionIndex to the index of
    >> the object within arrangedObjects.
    >> This works pretty good, but I wonder if there is a more
    >> convenient way to perform this, something like
    >> "selectObjectWithValueForKey". Is there a way to do
    >> this?
    >>
    >> Many thanks in advance,
    >> Michael
    >> --
    >> GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
    >> Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/
    >> freemail
    >>
    >
    > Hank Heijink
    > <hank.list...>
  • > One option would be to fetch objects matching your criteria (attribute
    > == 1) and then [myArrayController setSelectedObjects:fetchResults];
    >
    That might be a problem because the NSArrayController's content set is bound to the
    selection of another NSArrayController. What method is called when I
    select an object within the first NSArrayController? Maybe I can reimplement this method to make the controller select the desired object itself rather than from outside of the controller.

    MfG
    Michael

    > Wil
    >
    > On Jan 4, 2008, at 11:41 AM, Hank Heijink wrote:
    >
    >> Since there's only one entity that can be YES, you'd be faster and
    >> less memory-consuming if you just stored the index of the element
    >> that has YES, instead of storing YES/NO for every element and then
    >> having to find the right one.
    >>
    >> On Jan 4, 2008, at 2:32 PM, Michael Varlik wrote:
    >>
    >>> Hi,
    >>>
    >>> I have an NSArrayController which controles entities.
    >>> These entities have a boolean attribute and there is
    >>> exactly one entitie where this attribute is YES, all
    >>> the others are NO. When I want to select the one entity
    >>> with the attribute set to YES, I iterate through the
    >>> NSArrayController's arrangedObjects and when I find
    >>> the entity, I call setSelectionIndex to the index of
    >>> the object within arrangedObjects.
    >>> This works pretty good, but I wonder if there is a more
    >>> convenient way to perform this, something like
    >>> "selectObjectWithValueForKey". Is there a way to do
    >>> this?
    >>>
    >>> Many thanks in advance,
    >>> Michael
    >>> --
    >>> GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
    >>> Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/
    >>> freemail
    >>>
    >>
    >> Hank Heijink
    >> <hank.list...>


    --
    Psssst! Schon vom neuen GMX MultiMessenger gehört?
    Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger?did=10
  • > I have an NSArrayController which controles entities.
    > These entities have a boolean attribute and there is
    > exactly one entitie where this attribute is YES, all
    > the others are NO. When I want to select the one entity
    > with the attribute set to YES, I iterate through the
    > NSArrayController's arrangedObjects and when I find
    > the entity, I call setSelectionIndex to the index of
    > the object within arrangedObjects.

      It'd be easier to make recommendations if you described your goal a
    bit more broadly. What is this attribute used for? Why does selection
    depend upon it? What makes the attribute "YES"? What mechanism do you
    use to ensure only one entity instance has "YES" for the attribute?

    --
    I.S.
  • -------- Original-Nachricht --------
    > Datum: Fri, 4 Jan 2008 15:21:17 -0500
    > Von: "I. Savant" <idiotsavant2005...>
    > An: "Michael Varlik" <M.Varlik...>
    > CC: <cocoa-dev...>
    > Betreff: Re: Selecting an object of a NSArrayController

    >> I have an NSArrayController which controles entities.
    >> These entities have a boolean attribute and there is
    >> exactly one entitie where this attribute is YES, all
    >> the others are NO. When I want to select the one entity
    >> with the attribute set to YES, I iterate through the
    >> NSArrayController's arrangedObjects and when I find
    >> the entity, I call setSelectionIndex to the index of
    >> the object within arrangedObjects.
    >
    > It'd be easier to make recommendations if you described your goal a
    > bit more broadly. What is this attribute used for? Why does selection
    > depend upon it? What makes the attribute "YES"? What mechanism do you
    > use to ensure only one entity instance has "YES" for the attribute?
    >
    The attribute indicates which of the objects is the "active" one.
    The content set of the controller is bound to the selection of another
    array controller.
    On adding a new object to the array, I check if it is the first
    object in the array. if yes, the attribute becomes YES, otherwise
    it becomes NO. The user can change the attribute via a checkbox in
    a table column. When one of the checkboxes is clicked, I iterate
    through the arrangedObjects array of the controller and set all
    the attributes to NO except the one in the row which was clicked.

    MfG
    Michael

    > --
    > I.S.

    --
    GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
    Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today