Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

duggram

macrumors 6502
Original poster
Apr 17, 2008
391
11
I'm working on the Speakline exercise in the Hillegass Cocoa Programming book. In Chap. 6 up to page 105. When I run the app I get no values in the table. I do get this error message:

Illegal NSTableView data source (<AppController: 0x133dd0>). Must implement numberOfRowsInTableView: and tableView:eek:bjectValueForTableColumn:row:

I have triple checked all code and IB maneuvers. I have checked his web page for errata, there is something unrelated for page 106.

I downloaded his solutions code. His solution Speakline_B looks nothing like the code in the book at this point.

I searched the Web for others that may have the same problem. No solutions.

Any advice on how I can get values to show up in the table? And, eliminate the error code?

BTW here's my code:

AppController.m
Code:
#import "AppController.h"


@implementation AppController

- (id)init
{
	[super init];	
	NSLog(@"init");
	
	// create new instance of NSSpeechSynthesizer
	speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
	[speechSynth setDelegate:self];
	[tableView setDelegate:self];
	voiceList = [[NSSpeechSynthesizer availableVoices] retain];
	return self;
}

- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender
		didFinishSpeaking:(BOOL)complete;
{
	NSLog(@"complete = %d", complete);
}

- (IBAction)sayIt:(id)sender
{
	NSString *string = [textField stringValue];
	
	// Is the string zero-length
	if ([string length] == 0) {
		NSLog(@"string from %@ is of zero-length", textField);
			  return;
	}
	[speechSynth startSpeakingString:string];
	NSLog(@"Have start to say: %@", string);
	[stopButton setEnabled:YES];
	[startButton setEnabled:NO];
}

- (IBAction) stopIt:(id)sender
{
	NSLog(@"stopping");
	[speechSynth stopSpeaking];
	[stopButton setEnabled:NO];
	[startButton setEnabled:YES];
}

- (int)numberOfRowsInTableview:(NSTableView *)tv 
{
	return [voiceList count];
}

-(id)tableView:(NSTableView *)tv
		objectValueForTableColumn:(NSTableColumn *)tableColumn
						row:(int)row
{
	NSString *v = [voiceList objectAtIndex:row];
	NSDictionary *dict = [NSSpeechSynthesizer attributesForVoice:v];
	return [dict objectForKey:NSVoiceName];
	//return v;
}

@end

AppController.h

Code:
#import <Cocoa/Cocoa.h>


@interface AppController : NSObject {
	IBOutlet NSTextField *textField;
	IBOutlet NSButton *stopButton;
	IBOutlet NSButton *startButton;
	IBOutlet NSTableView *tableView;
	NSArray *voiceList;
	NSSpeechSynthesizer *speechSynth;

}
- (IBAction)sayIt:(id)sender;
- (IBAction)stopIt:(id)sender;
@end
 
I am giantly impressed with Aaron Hillegass. Late yesterday I posted this thread here, sent Aaron a message through his Web site, and went to bed. Soon after that Aaron sent me a message with the solution. Of course I'm embarrassed. But I'm also thankful that Aaron is so good to do what he did. It's been a long time (8+ yrs) since I've done any programming. I just don't have my ways back yet.

Thank you Aaron for taking the time, and thank you kainjow too,
Doug
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.