> ------------------------------
> 
> Message: 3
> Date: Fri, 23 May 2008 07:43:31 -0400
> From: "John Love" <[EMAIL PROTECTED]>
> Subject: NSProgressIndicator -- delete the first message
> with same
>       title
> To: "Cocoa Development"
> <cocoa-dev@lists.apple.com>
> Message-ID:
>       <[EMAIL PROTECTED]>
> Content-Type: text/plain; charset=ISO-8859-1
> 
> I have successfully been able to create a small Cocoa
> multiple document
> project whose GUI consists of a NSProgressIndicator, or
> wheel, and a Button,
> titled "Spin". In the .nib window, the
> "Controller" is ctrl-dragged to the
> wheel, specifying an outlet "wheel" and the
> Button is ctrl-dragged to the
> Controller, specifying an action :spin:".
> 
> Within the Controller.h file, I have:
> 
> @interface Controller:NSObject {
>     IBOutlet NSProgressIndicator *spinner;
>     BOOL start;
> }
> 
> - (IBAction) spin:(id)sender;
> 
> 
> Within the Controller.m file, I have:
> 
> @implementation Controller
> 
> - (id) init {
>     if (self = [super init]) {
>         spinner = [[[NSProgressIndicator alloc] init]
> autorelease];
>         start = TRUE;
>     }
> 
>     return self;
> }
> 
> 
> - (void) awakeFromNib {
>     [spinner setUsesThreadedAnimation:YES];
> }
> 
> 
> - (IBAction) spin:(id)sender {
>     if (start)  [spinner startAnimation:nil];
>     else        [spinner stopAnimation:nil];
> 
>     start = !start;
> }
> 
> @end
> 
> ==========
> 
> Works like a champ .. pressing the Button starts, stops the
> spinning like it
> should.
> 
> NOW .. another "speed bump" .. how to control the
> spinning from other
> objects, i.e., no IBAction .. so, remove the Button.
> 
> Changing the spin method to look like:
> 
> - (void) spinIt:(BOOL)begin {
>     if (begin)  [spinner startAnimation:nil];
>     else        [spinner stopAnimation:nil];
> }
> 
> Here is what I've tried, with no success:
> 
> Within MyDocument.h
> 
> @interface MyDocument:NSDocument
> {
>     IBOutlet Controller *theControl;
> }
> @end
> 
> 
> Within MyDocument.m
> 
> - (id) init {
>     if (self = [super init]) {
>         theControl = [[Controller alloc] init];
>     }
> 
>     return self;
> }
> 
> 
> - (void) awakeFromNib {
>     [theControl spinIt:TRUE];
> }
> 
> As I said above, it does not work; that is, I am not
> presented with a
> spinning wheel when the new window shows. Now, I have read
> about
> Notifications, Delegates in the Apple docs.  Clearly, I do
> not understand
> YET all of the info, but I'm getting there.  If I need
> to factor in
> Notifications and Delegates, I sure would appreciate a few
> snippets of
> guidance and in the process be able to more completely
> understand these
> beasts.
> 
> Thanks in advance,
> 
> John Love

Hi John,
There are several problems in your code which show, that you don not yet have 
an understanding how "freeze-drying" and then "thawing" of objects in the nib 
works.
First a couple of questions. What are your controller and document? Is the 
document a real subclass of NSDocument or you just name it so? Is the document 
an owner of the nib (Files's owner)?

Now to the comments:
1. You shouldn't create new NSProgressIndicator in the -init method of your 
Controller. The NSProgressIndicator outlet will get written into at the nib 
loading time because you control-dragged from controller to the indicator in 
your window: the instance in your window will get thawed.
2. Your code does work and does not crash because the outlet that you assigned 
in -init of your Controller gets overwritten later by nib loading code.
3. NSProgressIndicator that you allocated in the -init method and assigned to 
the outlet would crash your app if #2 didn't happen because you -autoreleased 
it (read memory management section in introductoryy docs for Cocoa).
4. You are allocating a new Controller in your -init of the Document that has 
absolutely no connection with the Controller that you created in the nib. You 
need to establish the connection with the one in the nib and you can do that in 
several ways. If your document is a File's owner of the nib, simply create an 
outlet for you controller in it and control-drag from Document to the 
Controller to establish connection. Then, in -awakeFromNib you should see, that 
your controller outlet is populated with instance of Controller from the nib 
and second part of your code should work.

In short: You should review do documentation about nib loading, outlets and 
actions. I am not at my development computer right now, so someone else can 
point you to relevant sections in introductory docs.

Hope that helps,
Gorazd



      __________________________________________________________________
Ask a question on any topic and get answers from real people. Go to Yahoo! 
Answers and share what you know at http://ca.answers.yahoo.com
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to