Re: Reaching the limits of 'learn by example'
Re: Reaching the limits of 'learn by example'
- Subject: Re: Reaching the limits of 'learn by example'
- From: Cyril Godefroy <email@hidden>
- Date: Sun, 13 May 2001 23:25:51 +0200
On Sunday, May 13, 2001, at 11:14 PM, Stefan Arentz wrote:
>
>
What you get back is the NSMenuItem that was selected. From the menu
>
item
>
you request it's 'represented object' or tag value. Both should just
>
work
>
so I think there's something wrong with the code that sets up the menu.
>
>
Maybe you can post the relevant code for your docket, I'm sure we can
>
find out what's causing this.
>
>
Stefan
Here are the relevant parts of the code:
-(void) itemSelected:(id)sender
{
NSString *level = [sender representedObject];
Float32 intLevel=0.1; //testing
//Float32 intLevel = [level intvalue]/6;
NSLog(@"level is:%@",level);
OSStatus err = noErr;
UInt32 count, muteSetting, channel, datasize;
if (intLevel == 0) {
isMute = YES;
muteSetting = 1;
} else {
isMute = NO;
muteSetting = 0;
}
count = sizeof(UInt32);
channel = 0;
err = AudioDeviceSetProperty(audioDevice, 0, channel, false,
kAudioDevicePropertyMute, count, &muteSetting);
datasize = sizeof(intLevel);
// Still work to understand there
// err = AudioDeviceSetProperty(audioDevice, 0, channel, false,
kAudioDevicePropertyVolumeScalar, datasize, &intLevel);
}
-(NSMenu*)menu
{
int i;
NSString * tString;
static char tCString[10];
NSMenu *newMenu = [[NSMenu alloc] initWithTitle:@"Mute"];
NSMenuItem *menuItem;
for ( i=0; i<7; i++){
sprintf(tCString,"%hd",i);
tString=[NSString stringWithCString:tCString];
menuItem = [[NSMenuItem alloc] initWithTitle:tString
action:@selector(itemSelected:) keyEquivalent:@""];
[menuItem setTarget:self];
[menuItem setRepresentedObject:tString];
[newMenu addItem:menuItem];
[menuItem release];
}
[self setMenu:newMenu];
[newMenu release];
return [super menu];
}
This won't compile because of the NSLog line. If I comment it, it
compiles, and I get my menu with all the values 0-6. As the NSLog won't
compile, I'm unable to check that the representedObject has been set to
the appropriate value.
Cyril Godefroy
www.macosxfr.com
The first Mac Os X Developer FAQ I know of