Last week I picked up the Aaron Hillegass Cocoa Programming fro Mac OS X, Second Edition book. Thought I might work it through and gain some proficiency with Object-C. So far I have completed the first five chapters including the Challenge exercises. Most of my time has been spent working the challenge exercises in chapter 4 & 5. Actually, the time was spent looking at the class documentation and figuring out how to implement a Delegate. Completing the exercise really made me feel stupid. It was actually so simple, but took several attempts over a three-day period to get it to work. Part of the problem is that at work use MS Visual Studio and code .Net C#. In this environment I use intelle-sense and seldom need to look at class documentation. However, the xcode IDE does not have this feature.
Today I learned that if I made a connection between my application window and the instance of my application using the window delegate, added the delegate definition to the .h file
– (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize;
and implemented it in the .m file I could control the widow size as the window was resized by the user.
– (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize
{
frameSize.height = frameSize.width * .5;
return frameSize;
}
What it really amounts to is the adding the definition of the delegate and returning its frameSize in the implementation. The coding paradigm is so different in Cocoa.