Re: IBOutlets and savePanels
Re: IBOutlets and savePanels
- Subject: Re: IBOutlets and savePanels
- From: Jeff LaMarche <email@hidden>
- Date: Sat, 13 Jul 2002 19:18:36 -0700
On Saturday, July 13, 2002, at 06:20 PM, Andrew Merenbach wrote:
>
I have questions on two completely different things. The first is
>
about IBOutlets. In my program, I have a file, Controller.h, which has
>
in it:
>
>
IBOutlet NSTextField *textField;
>
>
However, in some other sample code, I've seen it also as:
>
>
IBOutlet id textField;
IBOutlet is simply a cue to Interface Builder and actually resolves to
void (I think or some other non-functional code). As for id, you should
try reading Apple's Objective-C documentation (they changed the name
recently, but it used to be "Object-Oriented Programming and the
Objective-C Language" and is a must-read if you're doing any Cocoa work.
Unlike a lot of official Apple docs, it's really a very good book
(probably because it was written by NeXT a long time ago).
Simply put, id is a pointer to any object. It is generally good form to
use the first version, but they will both perform identically. When you
use id, you give up compile-time type-checking. This is good when you
want it - it allows you to really exploit the dynamic nature of
objective-C, but when it's not needed, you're better off with the
explicit declaration.
>
My second question regards the save panel, which doesn't seem to work
>
when I try to use it as a sheet. I get a warning: "NSSavePanel does
>
not respond to..." when I use the following code, which I carefully
>
based off of an example elsewhere:
Sheet's are modal and asynchronous. You kick them off and they do what
they want while your code continues. In your case, runResult won't ever
equal NSOkButton because the user won't have had time to respond. What
you need to do is kick off the save panel as a sheet using
beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo,
and then pass the selector of a method you want called when the sheet
has been dismissed. That method whose selector you pass should look
something like this:
- (void)savePanelDidEnd:(NSWindow *)sheet returnCode:(int)returnCode
contextInfo:(void *)contextInfo;
In this method is where you would put your code to check to see if the
Okay button was pressed and then save the code.
From the two questions you asked, I would seriously recommend some
further reading. Of the ones that I've read, Aaron Hillegass' book is
the best (although there are a bunch of newer ones I haven't read). I
can't recommend Apple's "Learning Cocoa" book very highly, although
there's some useful stuff in there. I would also recommend the
Objective-C documentation. Print it out. Read it and then read it again.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.