For the more curious....Hillegas...page 121

Discussion in 'Mac Programming' started by mdeh, Mar 29, 2009.

  1. macrumors 6502

    Joined:
    Jan 3, 2009
    #1
    Hi all,
    At the end of each chapter, are little, I guess, extra bits of knowledge, for the "more curious" as to the workings of Cocoa. Well, unfortunately, I am one of those curious..and am not sure if the author means that the reader should be able to use the book's prior information presented to solve these issues. Anyway, perhaps the list would not mind if I delve into this a little more deeply. (Chapter 7...Key-Value coding, Key-Value Observing)



    The issue is how to ( if I read this correctly) establish KVO programmatically.

    Hillegass says: ( Here, the set up is... briefly. A window with a slider, and a label. The slider is bound to the AppController which acts as model/controller, updating a property of the AppController. In the initial setup, the label is bound to the property as an observer, and is updated for any changes in the value of the property...which works as expected.)

    Using this code.

    Code:
    [AppController addObserver:self forKeyPath:fido options:KeyValueObservingOld context:somePointer]
    From the appleDocumentation:


    I am trying to programmatically ( being more curious :) ) to do this, but there are many areas of confusion for me.


    1)
    Does Apple's documentation mean that each object in the nib, once fully initialized receive an "awakeFromNib"...so, Window will be loaded, and then once ready, Window will receive and awakeFromNib, or as **each** object within window is ready, ( slider, button, textfield) **each** one will receive an awakeFromNib?

    2) As the code used by Hillegas is an instance method, **where** would one place this code. It seems to imply that it would have to be placed in a class that represented the label? Or is this really just a curiosity, and not practical?

    Thank you in advance?
     
  2. macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #2
    Each object will receive awakeFromNib after all objects have been initialized and all outlets have been set.

    awakeFromNib is a good place, because you know you'll have your outlets set to initialized objects at that point.
     
  3. thread starter macrumors 6502

    Joined:
    Jan 3, 2009
    #3
    Eddie..just to make sure I am expressing myself correctly. By object you mean each file in the nib...(Window, [custom]Oject, Controller etc). What about the controls **within** a window(object), like the textfields, sliders, buttons etc. (I think you are saying that the awakeFromNib will be sent to the actual object in the nib, not each individual control within the object?)



    Depending upon how you answer the above ...and this may well be getting ahead of the book... would I have to have an object representing **that** particular (control) eg label called for example "labelController" and in *that* object's awakeFromNib implement the method addObserver: .....
    Hope this all makes sense.
     
  4. macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #4
    Well, each of those is an object. So if you have three UITextFields (or whatever), that's 3 objects (in addition to the other objects).

    Each of those will get awakeFromNib.

    Well, I would use the word "controlling" rather than "representing", but yes that's one way to do it.
     
  5. thread starter macrumors 6502

    Joined:
    Jan 3, 2009
    #5

    Good...thanks. You know...half, if not more with these languages is syntax...and often my confusion is due to not using the correct syntax. What is a little confusing with these side-journeys, is that I am never sure if Hillegass means one can use the information provided *so far* to implement something ( the above being a good example) or whether one has to go off on a tangent to figure this out.
     
  6. macrumors 6502a

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #6
    Yep, like any other subject, the people who get lazy with the nomenclature (or don't think it's important) early on will usually struggle for a very long time. That's true for any subject.

    So I went back and read the page in Hillegass that you're talking about. And I don't think he was trying to get you to solve anything there. He was just giving some additional background on the subject.
     
  7. thread starter macrumors 6502

    Joined:
    Jan 3, 2009
    #7
    Sadly...I am **too** curious? :D I was trying to implement this on my own...but soon ran into those roadblocks. I will mark it as something to come back to.
     

Share This Page