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 > Help with one of the examples from Building Cocoa Applications (O'Reilly)

Help with one of the examples from Building Cocoa Applications (O'Reilly)
Thread Tools
Forum Regular
Join Date: Jul 2002
Location: Australia
Status: Offline
Reply With Quote
Dec 8, 2002, 12:01 AM
 
Hi everyone... over the University summer holiday, I've decided to learn Objective-C and Cocoa, after initially messing about with it from some articles on macdevcenter.com.

I'm running OS X 10.2 with the version of the dev tools that came with it.

I ordered Learning Cocoa with Objective-C (2nd Edition) and Building Cocoa Applications as they were reasonably priced when bought together from Amazon.

I got through the Learning Cocoa book in a few days, and had no trouble understanding it or doing any of the examples. However, I'm having some trouble with some of the code in the MathPaper section of Building Cocoa.

I can't figure out why the following code isn't working:

- (void)textDidChangeNSNotification *)notification
{
NSString * key = [[[self window] currentEvent] characters];

// if key is equal to carriage return
if ( [key isEqualToString:@"\r"] ) { ...

Enter never seems to equal \r or \n, and I can't figure out why.. the page the code is on is 338. Using NSLog shows that it is getting the last character properly.

Can anybody help me get this working, or explain why the current code doesn't work?

edit: it's in the delegate class for an NSTextView, which is a subclass of NSWindowController.
(Last edited by asmodeus; Dec 8, 2002 at 12:15 AM. )
     
Mac Elite
Join Date: Sep 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Dec 8, 2002, 12:44 AM
 
NSTextView can send its action on a carriage return (it's an option in Interface Builder). Maybe that's consuming the carriage return?
Geekspiff - generating spiffdiddlee software since before you began paying attention.
     
Forum Regular
Join Date: Jul 2002
Location: Australia
Status: Offline
Reply With Quote
Dec 9, 2002, 10:49 PM
 
I looked for the option but can't seem to find it.

I've moved on in the book anyway, writing some smaller programs for the remaining part of that section of the book to follow the exercises.
     
Fresh-Faced Recruit
Join Date: Apr 2001
Status: Offline
Reply With Quote
Dec 13, 2002, 10:53 AM
 
Is your window's delegate outlet set to be you PaperController. PaperController should be set as the File's Owner in the PaperWindow.nib.
     
Forum Regular
Join Date: Jul 2002
Location: Australia
Status: Offline
Reply With Quote
Dec 14, 2002, 01:39 AM
 
Yep, I've got that set correctly.

I've probably missed something minor somewhere. It's now actually detecting the carriage return properly, which is very strange - I didn't change anything, just resaved the PaperWindow nib file without making any changes.

Thanks for the suggestion though.
     
   
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:56 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