首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >预期"(“在AVCaptureSession之前”)

预期"(“在AVCaptureSession之前”)
EN

Stack Overflow用户
提问于 2010-11-21 09:59:40
回答 3查看 1.4K关注 0票数 2

当我试图构建我的应用程序时,XCode向我显示了这个错误

期望值“( AVCaptureSession之前)

有人能帮我修一下这个警告吗?这是我的密码:

ViewController.h

代码语言:javascript
复制
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>

@interface ViewController : UIViewController
{
}

- (IBAction)SwitchON_Flash;
- (void)setTorchSession:(AVCaptureSession *)CaptureSession;

@end

ViewController.m

代码语言:javascript
复制
#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 ///
{
}

谢谢!

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-11-21 10:03:49

默认情况下,UIViewController没有该方法。您没有该方法的实现,因此它会给出警告。如果您尝试运行此代码-您将得到“未知选择器发送到实例”错误。

您必须在视图控制器中为torchSession添加属性,或者实现该特定方法。

票数 1
EN

Stack Overflow用户

发布于 2010-11-21 10:11:10

第一个答案不一定正确,因为您可能已经实现了该方法,但根本没有在头文件中声明它。

在收到警告的行上,您将向self (在本例中是视图控制器)发送一条消息,以便使用参数setTorchSession运行方法CaptureSession。

如果您已经在您的setTorchSessin文件中实现了.m方法,那么您所要做的就是在您的接口(.h文件)中声明它,在SwitchON_Flash方法下添加以下行:

代码语言:javascript
复制
- (IBAction)SwitchON_Flash;
- (void)setTorchSession:(AVCaptureDeviceSession*)captureSession;

如果您还没有在实现文件中获得该方法,则应用程序将使用“未识别的选择器发送到实例”消息崩溃。

票数 1
EN

Stack Overflow用户

发布于 2010-11-21 11:14:19

你确定这门课是AVCaptureDeviceSession吗?我在XCode的帮助里根本找不到。

也许你是说AVCaptureSession

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4237295

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档