-2

我在 void is it says undeclared identifier for sliderDidChange 的行上遇到了这个错误,有人可以帮我解决这个问题,我找不到任何答案。

H。文件

//
//  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.文件

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];
}

有人可以帮忙吗

4

2 回答 2

0

那么问题可能是您{在该代码行上方的任何位置添加了

请确保所有打开的大括号都正确闭合

于 2013-04-02T18:38:58.383 回答
0

我假设 1)您已经在 .m 文件中综合了您的属性,2)您已经实现了 .h 文件中声明的所有方法,以及 3)您创建localslider对象的 .m 文件中的 6 个语句,即后面的-(void)sliderDidChange:(UISlider *)slider, 是viewDidLoad方法的一部分。
在这种情况下,您应该只收到一条警告,即slider您的-(void)sliderDidChange:(UISlider *)slider方法的参数隐藏了此方法中具有相同名称的实例变量。

于 2013-04-03T06:25:50.273 回答