Subclassing NSArrayController?

  • Hi,

    I have an ArrayController in IB to manage an array of NSObjects (a
    custom class) for a TableView.  When a new item is inserted via a
    button connected to insert: a new instance of my class is created and
    appears in the table.  However, I want to be able to control the
    property values of the new object at the time it is created.

    So, my class has a property called timeString.  The timeString is
    different for each object and is based on the time showing on a
    stopwatch (NSTextField) when the object is created.  Do I need to
    subclass NSArrayController and override the insert method in order to
    deal with getting this value and assigning it to the object at
    creation or would Key Value Observing in my Controller class be more
    effective?  What is the standard way of doing this?  Perhaps there is
    a way to bind the new object's property to the NSTextField value via
    IB and still make it so it never changes?

    Best Regards,
    Chris Poliquin
    -----------------------------
    <poliquin...>
    www.chrispoliquin.com
  • Subclass and override newObject which is declared in
    NSObjectController.h

    You can set any properties you like from there.

    ---------------------
    RONZILLA

    On Aug 19, 2008, at 7:27 AM, Chris Poliquin <poliquin...>
    wrote:

    > Hi,
    >
    > I have an ArrayController in IB to manage an array of NSObjects (a
    > custom class) for a TableView.  When a new item is inserted via a
    > button connected to insert: a new instance of my class is created
    > and appears in the table.  However, I want to be able to control the
    > property values of the new object at the time it is created.
    >
    > So, my class has a property called timeString.  The timeString is
    > different for each object and is based on the time showing on a
    > stopwatch (NSTextField) when the object is created.  Do I need to
    > subclass NSArrayController and override the insert method in order
    > to deal with getting this value and assigning it to the object at
    > creation or would Key Value Observing in my Controller class be more
    > effective?  What is the standard way of doing this?  Perhaps there
    > is a way to bind the new object's property to the NSTextField value
    > via IB and still make it so it never changes?
    >
    >
    > Best Regards,
    > Chris Poliquin
    > -----------------------------
    > <poliquin...>
    > www.chrispoliquin.com
  • This is maybe an answer as well as a question.

    Doesn't the bindings call the init method when creating a class
    object? Couldn't you just overwrite the init method on your custom
    class to set any necessary values?

    Justin Giboney

    On Aug 19, 2008, at 8:27 AM, Chris Poliquin wrote:

    > Hi,
    >
    > I have an ArrayController in IB to manage an array of NSObjects (a
    > custom class) for a TableView.  When a new item is inserted via a
    > button connected to insert: a new instance of my class is created
    > and appears in the table.  However, I want to be able to control the
    > property values of the new object at the time it is created.
    >
    > So, my class has a property called timeString.  The timeString is
    > different for each object and is based on the time showing on a
    > stopwatch (NSTextField) when the object is created.  Do I need to
    > subclass NSArrayController and override the insert method in order
    > to deal with getting this value and assigning it to the object at
    > creation or would Key Value Observing in my Controller class be more
    > effective?  What is the standard way of doing this?  Perhaps there
    > is a way to bind the new object's property to the NSTextField value
    > via IB and still make it so it never changes?
    >
    >
    > Best Regards,
    > Chris Poliquin
    > -----------------------------
    > <poliquin...>
    > www.chrispoliquin.com
    >
previous month august 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