Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Dumb Cocoa newbie question.

Dumb Cocoa newbie question.
Thread Tools
Forum Regular
Join Date: Nov 2001
Location: New Jersey, USA
Status: Offline
Reply With Quote
Oct 15, 2002, 11:59 PM
 
I just started learning Cocoa w/ Project Builder and Interface Builder, thanks to the wonderful MacOS X Developer's Guide.

I'm trying to create my first "test app" after reading most of the book... I basically wanted to make an EXTREMELY stripped down version of Diary, which I call SimpleDiary that has two classes: DiaryDocument and DiaryEntry. In DiaryDocument I declare the outlets (which is just an NSTextField for date and NSTextView for the entry). Then, I declare accessors and changers in DiaryDocument that will call the accessors and changers in DiaryEntry.

I've created my interface and now I simply want to connect my textfield and textview to their respective outlets, but when I try to connect the textfield to File's Owner, nothing comes up in "target".

I know I'm quite possibly doing this completely the wrong way but the book just doesn't seem to explain this when doing this from scratch, it only teaches you why certain lines of code are in the example provided with the text.

Can anyone get me started in the right direction here? Thanks!
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Oct 16, 2002, 06:23 AM
 
Originally posted by Mike the Knife:
I just started learning Cocoa w/ Project Builder and Interface Builder, thanks to the wonderful MacOS X Developer's Guide.

I'm trying to create my first "test app" after reading most of the book... I basically wanted to make an EXTREMELY stripped down version of Diary, which I call SimpleDiary that has two classes: DiaryDocument and DiaryEntry. In DiaryDocument I declare the outlets (which is just an NSTextField for date and NSTextView for the entry). Then, I declare accessors and changers in DiaryDocument that will call the accessors and changers in DiaryEntry.

I've created my interface and now I simply want to connect my textfield and textview to their respective outlets, but when I try to connect the textfield to File's Owner, nothing comes up in "target".

I know I'm quite possibly doing this completely the wrong way but the book just doesn't seem to explain this when doing this from scratch, it only teaches you why certain lines of code are in the example provided with the text.

Can anyone get me started in the right direction here? Thanks!
I think you are trying to connect to the wrong Object.

The outlets are in DiaryDocument - not NSApplication (which is what "File's Owner" points to (IIRC))

I think the step you forgot was to Instantiate an instance of your DiaryDocument Class.

This instance appears in your nib as a blue cube - connecting to this should allow you to hook-up your outlets.



[edit]
to instantiate a class right-click the Class in the Classes tab and select "instantiate"

(Last edited by Diggory Laycock; Oct 16, 2002 at 06:28 AM. )
     
Forum Regular
Join Date: Nov 2001
Location: New Jersey, USA
Status: Offline
Reply With Quote
Oct 16, 2002, 12:47 PM
 
Okay, I went to MainMenu.nib and found my document class and instantiated it -- but it actually created the object within the DiaryDocument.nib -- is that normal?

I'm assuming now I need to add outlets to the DiaryDocument instantiation, correct? I'll add my dateField and entryField outlets and then connect them to their appropriate fields?
(Last edited by Mike the Knife; Oct 16, 2002 at 01:10 PM. )
     
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status: Offline
Reply With Quote
Oct 16, 2002, 01:06 PM
 
Note: this was written BEFORE you instantiated your document in the nib. You do NOT do that.



What you need to do in the Document nib file is go to the classes tab. Then, go the the Classes menu and select "Read Files..." At this point, select your document subclass.

Then, go back to the Instances tab. Select Files Owner. Go to the Tools menu and select "Show Info." Select the Popup menu in the Show Info window and select Custom Class. Then, select your document subclass.

In your Document implementation file, you must implement the following function:

- (NSString *)windowNibName
{
return @"NibFileName";
}

Remember to leave out the .nib at the end of the NibFileName.


So, just remember that you must have Interface Builder read the header files for any of your classes that you want to use in Interface Builder. You may also need to instantiate that object. (If it's the owner of the nib file, it's already been instantiated elsewhare.) Note that it is often easier to instantiate objects in the nib file than it is in code... especially if you want access to other stuff in the nib file.

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Forum Regular
Join Date: Nov 2001
Location: New Jersey, USA
Status: Offline
Reply With Quote
Oct 16, 2002, 01:33 PM
 
Oh, I gotcha. Thanks a lot.

I think maybe I'm just starting this the wrong way. Any suggestions for easiest way to go about learning how to do my first project from scratch (this is Cocoa-Java by the way)? This book I got (although wondeful), doesn't really explain how projects actually come about from the beginning. I don't remember reading anything at all about needing to instantiate my document class.

Any suggestions welcome, and thanks again.
     
Professional Poster
Join Date: Apr 2001
Location: Long Beach, CA
Status: Offline
Reply With Quote
Oct 16, 2002, 01:50 PM
 
I would think a Document-based project would be a MORE difficult way to start. You might just want to start with a simple game.

ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
     
Mac Elite
Join Date: Sep 2000
Location: Edmond, OK USA
Status: Offline
Reply With Quote
Oct 16, 2002, 04:25 PM
 
Did you do the Java temperature converter?

It isn't document-based, but it does use outlets, etc.

http://developer.apple.com/techpubs/...vatutorial.pdf
     
Forum Regular
Join Date: Nov 2001
Location: New Jersey, USA
Status: Offline
Reply With Quote
Oct 16, 2002, 06:08 PM
 
Yep, I actually stumbled upon that today and realized that the book I got probably assumed that I do all the tutorials first. I did them, and everything started to make a LOT more sense. Not only did I learn a lot, but I got my test app to run.

Thanks everyone! Good to have a platform to develop on and feel cared about by not only the PC/OS manufacturer, but also the dev-community
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 01:55 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2