Undeclared Identifier after the void

2019-09-20 01:46发布

问题:

I have got this error on the line where the void is it says undeclared identifier for sliderDidChange can some one please help me with this i can;t find any answers.

h. file

//
//  LightViewController.h
//  Flash Light
//
//  Created by John Whitney on 12-07-27.
//  Copyright (c) 2012 Perfect Programs. All rights reserved.
//
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface LightViewController : UIViewController {
IBOutlet UISlider *slider;
IBOutlet UISlider *theslider;
IBOutlet UISlider *customslider;
UIButton *onButton;
UIButton *offButton;
UIImageView *onView;
UIImageView *offView;
}

@property(nonatomic, strong) IBOutlet UIButton *onButton;
@property(nonatomic, strong) IBOutlet UIButton *offButton;
@property(nonatomic, strong) IBOutlet UIImageView *onView;
@property(nonatomic, strong) IBOutlet UIImageView *offView;
@property(nonatomic, readonly) float torchLevel;

-(void)sliderDidChange:(UISlider *)slider;
-(BOOL)setTorchModeOnWithLevel:(float)torchLevel error:(NSError **)outError;
-(BOOL)supportsAVCaptureSessionPreset:(NSString *)preset;
-(IBAction)torchOn:(id)sender;
-(IBAction)torchOff:(id)sender;
@end

m.file

UISlider *localslider = [[UISlider alloc] initWithFrame:CGRectMake(20.0f, 20.0f, 280.0f, 40.0f)];
localslider.maximumValue = 1.0f;
localslider.minimumValue = 0.0f;
[localslider setContinuous:YES];
[localslider addTarget:self action:@selector(sliderDidChange:)  forControlEvents:UIControlEventValueChanged];
[self.view addSubview:localslider];


-(void)sliderDidChange:(UISlider *)slider
{

AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[device lockForConfiguration:nil];
[device setTorchModeOnWithLevel:slider.value error:NULL];
[device unlockForConfiguration];
}

can someone please help quick

回答1:

Well the problem may be you added an { anywhere above that line of code

Please make sure all open braces are closed properly



回答2:

I assume 1) you have synthesized your properties in the .m file, 2) you have implemented all methods declared in the .h file also there, and 3) the 6 statements in your .m file with which you create your localslider object, i.e. those followed by -(void)sliderDidChange:(UISlider *)slider, are part of the viewDidLoad method.
In this case, you should only get a warning that the argument slider of your -(void)sliderDidChange:(UISlider *)slider method hides your instance variable with the same name in this method.