I am new to Objective-C and am really stuck on this (Xcode 4.2.1 under Lion 10.7.2). I have tried it a couple of different ways, modeling the discussion in this Chapter, but then ended up trying the approach used by Adam in his solutions (downloaded from the Book’s website), but I still couldn’t get it to work. To that end, I made a Class delegate called MyClass; *.h and *.m code is below. I also listed the code for Ch6DelegateApp.h and Ch6DelegateApp.m files (see below) that were created with the Cocoa App. One problem seems to be that I am unable to connect the Window “Outlet”->delegate to MyClass.h (either programmatically or graphically, I can see this by right clicking on the Window Icon on the Xcode IB Dock). But I can see that the Window “Referencing Outlets” is connected to my Ch6Delegate.h file.
Files are below, please help! Thanks.
// Intended as the app-delegate class
@interface MyClass : NSObject <NSWindowDelegate>
I guess one key point is that conforming protocol is announced in the *.h file above (e.g., p. 101).
Then the corresponding m-file is:
// same code as Adam for the method:
- (NSSize)windowWillResize:(NSWindow *)sender toSize:(NSSize)frameSize
NSSize newSize = frameSize;
newSize.height = newSize.width * 2;
The *.h and *.m files that were created with the Cocoa App are:
@interface Ch6DelegateApp : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
and then the *.m file:
@synthesize window = _window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
// Insert code here to initialize your application