PDA

View Full Version : Help with Challenge exercise in Cocoa Programming for OS X Ch.6




RobCurie
Jun 26, 2008, 09:50 AM
Hello,

Has anyone used the new edition of Cocoa Programming for OS X? I'm a newbie to Objective-C and Mac programming, but I've been doing OOP programming in PHP for 3 years. I've been dabbling with C for a couple of months, so I feel comfortable enough reading and understanding Aaron Hillegass's book.

Anyway, in Chapter 6, after the discussion on dataSource, there is a challenge to make a Todo List application with a text field, a table view, and a button that adds the text from the text field to the table view.

I did this successfully, and was then ready to move on to the extra credit assignment: make the table view editable. The author even gives a hint: NSMutableArray has a method -replaceObjectAtIndex:withObject:.

Now I'm stuck. I'm thinking that I should use a delegate method for the table view and use the above method to replace the entry in the array. There are two specific problems I'm facing. The first is that I can't find the appropriate delegate method to use that will allow me to edit the row. The second is that even if I did know that delegate, I wouldn't know what to call the object that represents the row that I'm editing.

Any thoughts? suggestions?



RobCurie
Jun 29, 2008, 02:50 AM
Problem solved.

The solution was actually rather simple. I was blinded by trying to find a suitable delegate method for the NSTableView that I forgot to implement one of the necessary methods the DataSource protocol requires. I had forgotten to include -tableView:setObjectValue:forTableColumn:row:, which is necessary for making tableViews editable. The fact that this method is not mentioned in the documentation for NSTableView (because it is part of the NSTableDataSource protocol) caused my confusion.

Lesson learned: Learn what forces are directly behind your implementation. In this case, not the table view, but the data source.

yoavcs
Jun 29, 2008, 07:37 AM
Lesson #2: Apple's dev documentation needs some work. Luckily Cocoa is so intuitive, once you grasp the basic idioms, that you can get by even with the current docs.

RobCurie
Jun 29, 2008, 08:40 AM
I agree.

The API Documentation is quite esoteric, especially when trying to do something for the first time.

I actually found the solution to my problem in the "Table View Programming Guide" (http://developer.apple.com/documentation/Cocoa/Conceptual/TableView/TableView.pdf). It's written in plain English and explains table views in depth.

It wasn't easy finding this document.

Lesson #3: When searching the XCode Documentation, restrict the search by "Title", not "API". The results are way more read-friendly, and there are links to related methods, classes, and guides.