When adding a new row to the RaiseMan table via the ArrayController, both fields start off blank (name and raise). However, the Employee class defines defaults for both those properties. Is there a way to let the array controller keep these values when adding a new row to the table?
Answered my own question…
While looking into this a bit further, I discover that when the ArrayController creates new rows in the datasource of type [Employee], it doesn’t actually create new Employee objects, but instead creates NSMutableDictionaries.
Changed my ArrayController’s Class Name property (in the attribute inspector under section Object Controller) to RaiseMan.Employee, and now it creates Employee objects instead of mutable dictionaries as well as provides my default values assigned in the Employee class.
Hello
I just wanted to throw in my two cents. I think that the text should be revised to include a description of how to setup things up so that each time a new row is added the NSArrayController creates a new Employee instead of a NSMutableDictionary. When I ran the application after setting up the text field binding for the name attribute of the Employee object and hooking up the Add button for the first time I thought I must have made a mistake because the Name column didn’t display “New Employee” when I pressed the Add button. I didn’t manage to discover on my own the Object Controller attributes for the NSArrayController when I tried to figure out why the column didn’t show “New Employee”. It would be helpful if the text pointed out how to get this to work.
Thanks,
Rob
I may be misunderstanding the question, but the book walks you through setting the array controller’s Class Name attribute to RaiseMan.Employee on page 162, “Adding an Array Controller to the XIB”.
You were not misunderstanding the question. However, it appears the myself and two others missed it. I was on page 172 before I discovered I had missed this as it caused the app to crash after configuring the sort to the array controller. I am glad other people missed this and I was able to change it to get things to work. If we were watching something in person or on a video, we will see the instructor actually perform the actions described. In a book, you really have to pay attention less you gloss over a critical piece of information hiding (in plain sight) in the text. I am reading/doing this book in spurts and sometimes leave the book for days and can miss something. My suggestion is to format the instructions in a list, separate from the overall paragraph descriptive text. This way it is easier to see the instructions from the non instructions. You do show a screen shot on the next page which gave us another chance to get it right, but we must not have been paying attention combined with the fact that the reproduced screenshot is monochrome and a small font. To help with us non attentive people, color could be used to differentiate/highlight the changed/entered items in the screenshot, or if color is not an option, circle the appropriate items. As for the instruction list, I would put them in another font or bold. Of course getting enough sleep and being alert is always a good idea and is one of the most important things you state in the book early on : )
So at the bottom of page 162 “I” would show things this way:
The array controller needs to know what kind of object… <>
With the array controller still selected,
- switch to the attribute selector
- locate the Object Controller section
- Set the Class Name to RaiseMan.Employee