我创建了两个ViewControllers(Xcode 4 => Storyboard)。之后我创建了两个UIViewSubclasses,名为PlayOutControlViewController.h和TVOutViewController.h。
我想在外部显示器上显示视频,因此我尝试了以下操作:
(添加了MediaPlayer.framework,将我的UIViewSubclasses的类更改为PlayOut ...和TVOut ... - Controller.h)
PlayoutViewController.m
[TVOutViewController.view addSubview: MediaPlayer.view];
//Got Error: Property view not found on object of type TVOutViewController
[TVOutViewController addSubview: MediaPlayer.view]; //Got an Error
//Got Error: No known class method for selector addSubview
抱歉,我知道错误的含义,但不知道如何修复它们。
提前致谢!
P.S。我在PlayoutViewController.m中,其中:
[self.view addSubview: (anyUIView)];
//works
//and
[PlayoutViewController.view addSubview: (anyUIView)];
//won't work.
...谢谢!
答案 0 :(得分:1)
一个类及其实例是不同的东西。
self.view
有效,因为类PlayoutViewController的实例具有view
属性。
PlayoutViewController.view
没有,因为类对象本身没有此属性。这同样适用于TVOutViewController - 你应该调用一个实例,而不是类本身。
答案 1 :(得分:1)
到目前为止,谢谢。
我的TVOutViewController是UIViewController的子类,如下所述:
@interface TVOutViewController : UIViewController { }
我在InterfaceBuilder中向TVOutViewController添加了一个UIView。我是否必须做其他事情才能做到:
[self.view addSubview: AnyUIView];
第二个问题:
如果我在TVOutViewController.m中声明一个方法,例如:
+(void)addSubviewMethod:(id)sender { [self.view addSubview: AnyUIView]; }
为什么我无法通过
在PlayoutControlViewController.m中调用它[TVOutViewController addSubviewMethod];
我添加了
#import "TVOutViewController.h";
到PlayOutViewController.m文件。
提前谢谢大家!
确定已解决:
你走在正确的轨道上:
我忘了初始化对象。现在它就像一个魅力!
TVOutViewController *MoviePlayerView = [[TVOutViewController alloc] init];
[MoviePlayerView.view addSubview:moviePlayer.view];