Cocoa: Let's Get Hammered!
Fri 19 June 2015
15:17:48
It's the programmer's choice for making pretty Mac OS X programs. Apple gives you tons of stuff for free--the development software and 1GB of documentation.
The software, a.k.a. XCode, is a very comprehensive package that includes a coding environment with all the bells and whistles a hardcore programmer could want, including a class browser, an interface builder called, strangely enough, Interface Builder, and a few dozen mini-utilities including an icon package builder and a USB probe, if you feel the need to probe your USB.
The documentation, on the other hand, leaves something to be desired. It's written by SuperGenii for Supergenii. If you are only a plain genius, then you are screwed. As well, if you are like me, you just need to see a specie of the method you want to use. It's faster and easier for my mind to grasp it and retain it. So, I will be posting a few simple posts to provide others who want a simple answer.
Good luck to all you intrepid coders and it's okay to screw up. Only you and the little hammer will know.
Oh, and if you find any mistakes, please let me know. I am human and need to be loved. syntonica at that yahoo thing dot com.
Will the Delegates from Table View please sit down?
Thu 25 June 2009
01:00:49
If you want to display a table using NSTableView, but you want to make it look all purty, with each little square different from the last, use:
-(void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex
Instead of delving into the cells one by one on your own, let the table present them to you with this delegate method. If you are using a data source, delegation is already set up. You only need to stuff your code into this method. You get the row as an integer, numbered from 0 on up. And you get the column, well, as a column. What more could you ask for?
From here, you can setFont:, setBackgroundColor, whatever your little hear desires. And while you are at it, don't forget about:
- (void)tableViewSelectionDidChange:(NSNotification *)aNotification
- (BOOL)tableView:aTable shouldSelectRow:(int)rowIndex
These handy delegate methods let you know when the user does something, like move to a different record. In that time, you can do stuff like save changes, populate data fields, etc.
Lesson of the Moral: don't eschew delegate methods. They make your life incredibly more simpler. Or however it goes...