error: 'fxVolumeSlider' undeclared (first use in this function) - Need to declare IBOUTLET?
Okay well now im trying to get the volume to change on the slider
here is the code
@implementation MainerViewController
@synthesize fxVolumeSlider;
- (IBAction)pushPlay:(id)sender; {
NSString *path = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"wav"];
if (theAudio) [theAudio release];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];
volumeTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(updateVolume) userInfo:nil repeats:YES];
}
-(void)updateVolume {
[theAudio setVolume:fxVolumeSlider.value];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Setup custom slider images
UIImage *minImage = [UIImage imageNamed:@"grey_track.png"];
UIImage *maxImage = [UIImage imageNamed:@"white_track.png"];
UIImage *tumbImage= [UIImage imageNamed:@"metal_screw.png"];
minImage=[minImage stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
maxImage=[maxImage stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0];
// Setup the FX slider
[fxVolumeSlider setMinimumTrackImage:minImage forState:UIControlStateNormal];
[fxVolumeSlider setMaximumTrackImage:maxImage forState:UIControlStateNormal];
[fxVolumeSlider setThumbImage:tumbImage forState:UIControlStateNormal];
fxVolumeSlider.minimumValue = 0.0;
fxVolumeSlider.maximumValue = 1.0;
fxVolumeSlider.continuous = YES;
//fxVolumeSlider.value = [sharedSoundManager fxVolume];
// Attach an action to sliding
[fxVolumeSlider addTarget:self action:@selector(fxSliderAction:) forControlEvents:UIControlEventValueChanged];
// Cle开发者_如何学JAVAanup
minImage = nil;
maxImage = nil;
tumbImage = nil;
}
- (void) fxSliderAction:(id)sender {
[theAudio setFxVolume:fxVolumeSlider.value];
}
However i now get this error
warning: 'AVAudioPlayer' may not respond to '-setFxVolume:'
So everytime i play the play button, i try to adjust the volume but i get kicked out of the app
You've declared both the ivar and the property as _fxVolumeSlider
but what you use within the method is fxVolumedSlider
. Both are not the same. You should use _fxVolumeSlider
or what you probably meant was to declare the property as
@property(retain, nonatomic) IBOutlet UISlider *fxVolumeSlider;
and synthesize it using
@synthesize fxVolumeSlider = _fxVolumeSlider;
But even then you can't use it as fxVolumeSlider
. You can use it as self.fxVolumeSlider
or _fxVolumeSlider
. If you want to use it as plain fxVolumeSlider
, you should replace all _fxVolumeSlider
s with fxVolumeSlider
.
Check the underscore in the declaration. In the .h file, you have:
IBOutlet UISlider *_fxVolumeSlider;
You should have:
IBOutlet UISlider *fxVolumeSlider;
Also, in the .m file, edit the line
@synthesize _fxVolumeSlider;
to be
@synthesize fxVolumeSlider;
As to your revised issue:
- (void) fxSliderAction:(id)sender {
[theAudio setFxVolume:fxVolumeSlider.value];
}
should instead read as
- (void) fxSliderAction:(id)sender {
[theAudio setVolume:fxVolumeSlider.value];
}
Watch out for typos (and look for them before posting!)
精彩评论