Buttons non responsive


#1

So I built the SpeakLine app as described on pages 85 - 90. Had a little trouble making the connections, because the expected actions were not showing up for the App Controller object after I placed it on the Doc window. I finally tried Building the app and then after that the connections were available. So then I made the connections as described. But when I run my app, it does not recognize Click events on either button. I added NSLog statements first thing in all methods … and the only one being executed is init. It surely SEEMS like the connections are not correct … but I’ve looked and looked and looked at them and the look ok to me. So I cannot figure out what else to check.

I followed the Debugging Hints at the end of Chapter 5 – specifically:

  • confirmed I have the four connections described. Even went so far as to remove them and then add them back, to make sure they were right or had not somehow been corrupted.
  • Checked spellings for each method, paying particular attention to Case.
  • Have followed execution via debugger to see what that tells me. I set a breakpoint in the init, then followed one line at a time after that. Execution goes through several NS classes, but the machine code got tiring and I figure I must have missed something basic … I just cannot figure out what it might be.

Any ideas / help?
Thanks in advance.

Code follows:
// AppController.h
#import <Cocoa/Cocoa.h>

@interface AppController : NSObject {
IBOutlet NSTextField *textField;
NSSpeechSynthesizer *speechSynth;
}

  • (IBAction)sayIt:(id)sender;
  • (IBAction)stopIt:(id)sender;

@end

// AppController.m
#import “AppController.h”

@implementation AppController
-(id)init
{
[super init];
NSLog(@“In init method for AppController Class”);
speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
return self;
}

  • (IBAction)sayIt:(id)sender
    {
    NSLog(@“In sayIt method”);
    NSString *string = [textField stringValue];
    if ([string length] == 0) {
    NSLog(@“string from %@ is zero length”, textField);
    return;
    }
    [speechSynth startSpeakingString:string];
    NSLog(@“Started speaking ‘%@’”, string);
    }
  • (IBAction)stopIt:(id)sender
    {
    NSLog(@“stopping synthesized speech”);
    [speechSynth stopSpeaking];
    }
    @end

#2

Not sure what the problem was, but I started from scratch with a new Xcode project file, copy/pasted my code in from the original .h and .m files, created new buttons and made the same connections I did initially … and it works perfectly! The only think I can figure is that I somehow corrupted something with all the unsuccessful attempts to make the connections the first time around.

Speaking of which … not only did I need to Build the class, but I also had to save the IB file (the second time around), before I could make the connections (the second time around).