当我试图构建我的应用程序时,XCode向我显示了这个错误
期望值“( AVCaptureSession之前)
有人能帮我修一下这个警告吗?这是我的密码:
ViewController.h
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
@interface ViewController : UIViewController
{
}
- (IBAction)SwitchON_Flash;
- (void)setTorchSession:(AVCaptureSession *)CaptureSession;
@endViewController.m
#import "ViewController.h"
@implementation ViewController
UIAlertView *NoFlash;
- (IBAction)SwitchON_Flash
{
AVCaptureDevice *Device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([Device hasTorch] && [Device hasFlash])
{
if (Device.torchMode == AVCaptureTorchModeOff)
{
AVCaptureDevice *Device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
AVCaptureDeviceInput *FlashInput = [AVCaptureDeviceInput deviceInputWithDevice:device error: nil];
AVCaptureVideoDataOutput *VideoOutput = [[AVCaptureVideoDataOutput alloc] init];
AVCaptureSession *CaptureSession = [[AVCaptureSession alloc] init];
[CaptureSession beginConfiguration];
[CaptureSession addInput:FlashInput];
[CaptureSession addOutput:VideoOutput];
[CaptureSession commitConfiguration];
[CaptureSession startRunning];
[Device lockForConfiguration:nil];
[Device setTorchMode:AVCaptureTorchModeOn];
[Device setFlashMode:AVCaptureFlashModeOn];
[Device unlockForConfiguration];
[self setTorchSession:CaptureSession];
[CaptureSession release];
[VideoOutput release];
}
else
{
[torchSession stopRunning];
}
}
else
{
NoFlash = [[UIAlertView alloc] initWithTitle:@"Uh-Oh"
message:@"Your device doesn't have a flash camera"
delegate:nil
cancelButtonTitle:@"mhmm, OK"
otherButtonTitles:nil];
NoFlash.delegate = self;
[NoFlash show];
[NoFlash release];
}
}
- (void)setTorchSession:(AVCaptureSession *)CaptureSession <== /// ERROR HERE ///
{
}谢谢!
发布于 2010-11-21 10:03:49
默认情况下,UIViewController没有该方法。您没有该方法的实现,因此它会给出警告。如果您尝试运行此代码-您将得到“未知选择器发送到实例”错误。
您必须在视图控制器中为torchSession添加属性,或者实现该特定方法。
发布于 2010-11-21 10:11:10
第一个答案不一定正确,因为您可能已经实现了该方法,但根本没有在头文件中声明它。
在收到警告的行上,您将向self (在本例中是视图控制器)发送一条消息,以便使用参数setTorchSession运行方法CaptureSession。
如果您已经在您的setTorchSessin文件中实现了.m方法,那么您所要做的就是在您的接口(.h文件)中声明它,在SwitchON_Flash方法下添加以下行:
- (IBAction)SwitchON_Flash;
- (void)setTorchSession:(AVCaptureDeviceSession*)captureSession;如果您还没有在实现文件中获得该方法,则应用程序将使用“未识别的选择器发送到实例”消息崩溃。
发布于 2010-11-21 11:14:19
你确定这门课是AVCaptureDeviceSession吗?我在XCode的帮助里根本找不到。
也许你是说AVCaptureSession
https://stackoverflow.com/questions/4237295
复制相似问题