PDA

View Full Version : Help needed with Chapter 5 Challenge from Cocoa Programming for Mac OS X




ExoticFish
Sep 11, 2006, 02:22 PM
I've been reading Cocoa Programming for Mac OS X and have been finding it enjoyable thus far. The challenge at the end of chapter 5 has been giving me fits however. I just can't make it work.

I've looked around online and it seems that everyone else's solutions are exactly what I'm doing but for some reason I can not get it to work.

here's (http://cocoatravels.blogspot.com/2005/10/chp-5-challenge-solution.html) a site that describes exactly how I tried to solve the problem but when I run the compiled application it does not work! I'm thinking that perhaps it could have something to do with the book's teaching of 10.3 instead of 10.4 but I've seen other people saying they were programming in 10.4

I'm trying to get this to work before I move on to chapter 6. Any help would be greatly appreciated!



whooleytoo
Sep 11, 2006, 03:06 PM
Just tried (on 10.4), and works fine here.

I'd imagine the most likely problems are the window's delegate hasn't been set, or there's a typo in the windowWillResize: method name? Other than that, I can't think what could be wrong - there's not a lot of code to get wrong! ;)

ExoticFish
Sep 11, 2006, 03:34 PM
ok here's what i'm doing:

* i made a subclass of NSObject called AppController, created files, and instantiate it

*AppController.h contains:

/* AppController */

#import <Cocoa/Cocoa.h>

@interface AppController : NSObject
{
}

- (NSSize)windowWillResize:(NSWindow *)sender
tosize:(NSSize)frameSize;

@end

*AppController.m contains:
#import "AppController.h"

@implementation AppController
{

}

- (NSSize)windowWillResize:(NSWindow *)sender
tosize:(NSSize)frameSize
{
NSLog(@"calling windowWillResize");
frameSize.width = frameSize.height * 2;
return frameSize;
}

@end

* in Interface Builder I ctrl drag from Window in the Instances tab to the Instance of AppController and connected the delegate

What am i missing?

whooleytoo
Sep 11, 2006, 03:41 PM
No, that looks pretty good actually.

I hope I don't sound condescending, but could you have forgotten to save the changes in the .nib file? Or perhaps when connecting the delegate, you clicked on "delegate" in the list, but never clicked "Connect" (or double clicked, which does the same thing)?

ExoticFish
Sep 11, 2006, 03:55 PM
hey I'm a noob to Cocoa to condescend away! :D But I did make sure to do both of those things. Here's an image of IB

ExoticFish
Sep 12, 2006, 11:54 PM
Ok now this is just driving me crazy. Would you mind send me your xcode project so i can test to see if it's just my machine or not? I'd greatly appreciate it!

whooleytoo
Sep 13, 2006, 07:00 AM
No problem, you should find it attached.

If nothing appears different, I can provide code that would check if the window's delegate is set correctly at run-time, this would seem to me to be the most likely problem.

ExoticFish
Sep 13, 2006, 02:56 PM
Wow

That's all i can really say.

I thank you for you help, but I found the problem finally. In my code posted here you will find my error. tosize: should be toSize:

nothing more to see here folks, move along!

:rolleyes:

seriously though, thanks for taking the time to help out a noob!

Catfish_Man
Sep 13, 2006, 03:08 PM
Wow

That's all i can really say.

I thank you for you help, but I found the problem finally. In my code posted here you will find my error. tosize: should be toSize:

nothing more to see here folks, move along!

:rolleyes:

seriously though, thanks for taking the time to help out a noob!

Ways to find that sort of problem:
1) use autocomplete a lot
2) read the compile warnings closely

Fairly
Sep 24, 2006, 06:03 PM
Off topic, but don't waste your time with that book. Get the Yacktman book instead.

slooksterPSV
Sep 24, 2006, 09:23 PM
Off topic, but don't waste your time with that book. Get the Yacktman book instead.
I strongly disagree with your post, I think that Cocoa Programming for Mac OS X was and still is an awesome book. It teaches you how to use Cocoa very benefitially.

To the Poster: when you finish the book, look up online tutorials for Core Data. OMG That is crazy, it is so cool that I mean I just wow, I created 2 apps in less than 1 hour. My MDM - MoneyData Manager, I recreated that in 10 min. with CoreData, it didn't have EVERYTHING in it, but it had the basics for what I wanted to do. I also made ADM - Assignment Data Manager. -This took longer because I wasn't sure how to do something, but it just automatically worked when I tried it, so yeah.

HiRez
Sep 25, 2006, 01:39 AM
I agree that the Hillegass book is the best introduction to Cocoa programming. However, the Anguish/Buck/Yacktman book (Cocoa Programming (http://www.amazon.com/Cocoa-Programming-Scott-Anguish/dp/0672322307/sr=1-2/qid=1159166062/ref=pd_bbs_2/002-0725349-3763236?ie=UTF8&s=books)) is also awesome. Where Hillegass is more of a tutorial approach, Anguish is more of a reference and sample-code approach. It's an excellent, comprehensive book, the only problem is it is very out of date (it's 4 years old). I believe it was written when Jaguar (10.2) was still pre-release. That means no discussion of Cocoa Bindings, no Core Data, no Core Image, "Xcode" didn't even exist, and it has some now-deprecated API listings. I still use it from time to time though, it's a shame they don't do a fresh update to it.

aquanutz
Sep 27, 2006, 11:12 PM
totally off topic, but i see you're from Kent. I go to BG. <from left field>

ExoticFish
Oct 1, 2006, 01:29 AM
so many responses, thanks.

@aquanutz
cool, not too far away then. never been to BG although I did drive past it once while heading somewhere. only thing I know about it over there is that a friend of mine went to his first year of college there before moving back and going to Kent.