使用未声明的标识符

时间:2013-10-05 18:45:40

标签: ios objective-c undeclared-identifier

[mpc [[MPMoviePlayerController alloc]] [[initWithContentURL:url]]]出现错误;它说initWithContentURL是一个Undeclared Indentifier。我该如何解决这个问题?

导入“ViewController.h”

@interface ViewController ()
{
    MPMoviePlayerController *mpc;
}

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)playButton:(id)sender {
    NSString *stringpath;[[NSBundle mainBundle]pathForResource:@"Lake Weekend September 13-14" ofType:@"m4v"];
    NSURL *url = [[[NSURL fileURLWithPath:stringpath]
    [mpc [[MPMoviePlayerController alloc]][[initWithContentURL:url]]];
    [mpc setMovieSourceType:MPMovieSourceTypeFile];

    [[self view ]addSubview:mpc.view];

    [mpc setFullscreen:YES];

    [mpc play];
}
@end

2 个答案:

答案 0 :(得分:0)

在使用之前你还没有声明url?你试图在声明中使用它......

NSURL *url = [[[NSURL fileURLWithPath:stringpath]
[mpc [[MPMoviePlayerController alloc]][[initWithContentURL:url]]];

你应该在第一行之后至少有一个半冒号..然后你就可以使用url了。另外,您需要整理额外的括号,试试这个..

NSURL *url = [NSURL fileURLWithPath:stringpath];
mpc = [[MPMoviePlayerController alloc]initWithContentURL:url];

答案 1 :(得分:0)

你的mpc的alloc / init看起来都错了。那条线对我来说都是乱码。我认为该行应该是这样的:

mpc=[[MPMoviePlayerController alloc] initWithContentURL: url];