-1

我想要两个 MPMoviePlayerControllers。所以我首先在点击按钮后将其添加到操作方法中:

MPMoviePlayerController *movieController= [[MPMoviePlayerController alloc] initWithContentURL: yURL];
[movieController prepareToPlay];
[movieController.view setFrame: self.view.bounds];  
[self.view addSubview: movieController.view];
[movieController play];

这行不通!我正在遵循这种方法,以便我可以在同一视图上添加另一个玩家。但是当我尝试将其添加到 .h

@property (nonatomic, strong) MPMoviePlayerControllers *moviePlayer;

这对.m

self.movieController= [[MPMoviePlayerController alloc] initWithContentURL: yURL
[self.movieController.view setFrame: self.view.bounds]; 
[self.view addSubview: self.movieController.view];
[self.movieController play];

它完美无缺!有人可以向我解释吗?以及如何在视图中添加多个视频播放器,例如填充每个单元格中都有一个播放器的表格?

4

1 回答 1

1

In the first example, you're declaring your movieController inside of the method. This means that the scope of the variable is the method, and when the method ends, the variable is deallocated. The subview that you added now doesn't point to anything, so the movie player doesn't show up.

When you declare the variable to be a property, it exists for the lifetime of your object. You can access and set its value as long as your object still exists. When you assign the value to the property, its value is being stored after the return of the method, so the view appears.

于 2013-09-02T01:58:05.100 回答