【问题标题】:expected expression error within function函数内的预期表达式错误
【发布时间】:2012-07-30 18:59:24
【问题描述】:

所以我正在尝试编写一个几乎只是播放媒体播放器的 IBAction 的函数。这在我正在编写的代码中是必要的,因为将使用多个视频,因此为了使我的代码更简洁,我想编写该函数,以便媒体播放器的代码进入一次而不是多次。当我尝试下面的代码时,它指出我在 IBAction 上有一个错误,指出“预期的表达式”。有任何想法吗?代码中还包含一个注释掉的 if 语句,该语句不起作用。基本上我希望这样当我单击全屏媒体播放器中提供的默认“完成”按钮时,窗口将关闭。现在所有完成按钮所做的只是停止视频,但我希望媒体播放器也关闭。

void moviePlayer (id vidName, id type);

void moviePlayer (id vidName, id type){


-(IBAction)playMovie{


NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"vidName" ofType:@"type"]];

MPMoviePlayerController *playerViewController = [[MPMoviePlayerController alloc] init];
playerViewController.contentURL = url;
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight){
    playerViewController.view.frame = CGRectMake(0, 0, 1030, 768);
}
else{
    playerViewController.view.frame = CGRectMake(0,0, 768, 1004);
}
[playerViewController setControlStyle: MPMovieControlStyleFullscreen];
[playerViewController setScalingMode:MPMovieScalingModeAspectFit];
playerViewController.view.AutoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:playerViewController.view];
[playerViewController play];
/*if (playerViewController == stop){
 [self.playerViewController.view removeFromSuperview];

 }*/

self.playerViewController = playerViewController;


}
}

【问题讨论】:

    标签: xcode function media-player fullscreen ibaction


    【解决方案1】:

    看这部分代码:

    void moviePlayer (id vidName, id type){
    
    
    -(IBAction)playMovie{
    

    你启动了一个 C 函数并且不关闭它,然后尝试启动 Objective C 方法。也许这会更好?

    void moviePlayer (id vidName, id type){
    }
    -(IBAction)playMovie{
        // other code
    }
    

    【讨论】:

    • 该括号不会关闭函数,以便 IBAction 不会包含在函数中。我觉得这会使函数变得无用,因为函数体中没有任何内容
    • 没错。您不能在函数中使用函数,在方法中使用方法或任何类似的 xxx 在 yyy 两者的组合中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-25
    • 1970-01-01
    • 1970-01-01
    • 2016-06-03
    • 1970-01-01
    • 1970-01-01
    • 2014-01-01
    相关资源
    最近更新 更多