下一个代码仅适用于LBYouTubePlayerController* controller;
在@implementation ViewController
之内。有人可以向我解释为什么我会得到这种行为,有什么区别?只有当我在实现中初始化对象时,代码才有效。
.h文件中:
#import <UIKit/UIKit.h>
#import "LBYouTube.h"
@interface ViewController : UIViewController<LBYouTubePlayerControllerDelegate>
@end
.m文件:
#import "ViewController.h"
@interface ViewController()
@end
@implementation ViewController
{
LBYouTubePlayerController* controller;
}
- (void)viewDidLoad
{
[super viewDidLoad];
controller = [[LBYouTubePlayerController alloc] initWithYouTubeURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=1UlbCgB9vms"] quality:LBYouTubeVideoQualityLarge];
controller.delegate = self;
controller.view.frame = CGRectMake(0.0f, 0.0f, 200.0f, 200.0f);
controller.view.center = self.view.center;
[self.view addSubview:controller.view];
如果我将继续前进LBYouTubePlayerController* controller;
并把它里面viewDidLoad
视频将不会加载:
- (void)viewDidLoad
{
LBYouTubePlayerController* controller = [[LBYouTubePlayerController alloc] initWithYouTubeURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=1UlbCgB9vms"] quality:LBYouTubeVideoQualityLarge];
controller.delegate = self; ....}
你使用ARC吗?无论哪种方式,您想要引用LBYouTubePlayerController。如果你没有使用ARC,那么你的内存泄漏没有引用,如果使用ARC,实例被解除分配,并且只有视图处于活动状态,这意味着LBYouTubePlayerController无法加载视图,调用方法等。 – TheBlack 2013-04-30 16:41:14
是的,xcode 4.6.2 – Segev 2013-04-30 16:42:11
这实际上是一个奇怪的方式。通常你会有一个视图控制器,但看起来像你使用两个。如果你没有保留属性引用,LBYouTubePlayerController将被释放。 – sosborn 2013-04-30 16:44:01