Xcode:ViewController 不显示 .view 或 addSubview:方法
我创建了两个 ViewController(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
抱歉,我知道什么错误意味着错误,但不包括如何修复错误。
提前致谢!
PS 我在 PlayoutViewController.m 中,其中:
[self.view addSubview: (anyUIView)];
//works
//and
[PlayoutViewController.view addSubview: (anyUIView)];
//won't work.
...谢谢!
I created two ViewControllers (Xcode 4 => Storyboard). After that I created two UIViewSubclasses, called PlayOutControlViewController.h and TVOutViewController.h.
I want to display a video on an external Display, so I tried the following:
(MediaPlayer.framework added, Changed the class of my UIViewSubclasses to PlayOut... and 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
Sorry, I know what the Errors mean, but not how to fix them.
Thanks in advance!
P.S. I'm in the PlayoutViewController.m, where:
[self.view addSubview: (anyUIView)];
//works
//and
[PlayoutViewController.view addSubview: (anyUIView)];
//won't work.
... Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
类和它的实例是不同的东西。
self.view
有效,因为类 PlayoutViewController 的实例具有view
属性。PlayoutViewController.view
没有,因为类对象本身没有这个属性。这同样适用于 TVOutViewController — 您应该调用一个实例,而不是类本身。A class and its instances are different things.
self.view
works, because instances of class PlayoutViewController haveview
property.PlayoutViewController.view
doesn't, because the class object itself does not have this property. The same applies to TVOutViewController — you should call an instance, not the class itself.到目前为止谢谢。
我的 TVOutViewController 是 UIViewController 的子类,如下所述:
我在 InterfaceBuilder 中向 TVOutViewController 添加了一个 UIView。我是否必须做其他事情才能做到类似:
第二个问题:
如果我在 TVOutViewController.m 中声明一个方法,例如:
为什么我无法通过
添加
到 PlayOutViewController.m 在 PlayoutControlViewController.m 中调用它文件。
提前谢谢大家!
好的解决了:
你走在正确的轨道上:
我忘记初始化对象。现在它就像一个魅力!
Thanks so far.
My TVOutViewController is a subclass of UIViewController, as described here:
I added a UIView to the TVOutViewController in InterfaceBuilder. Do I have to do something else to be able to do like:
Second question:
If I declare a method in TVOutViewController.m, like:
Why am I not able to call it in the PlayoutControlViewController.m via
I added
to the PlayOutViewController.m file.
Thank you all in advance!
OK SOLVED:
You were on the right track:
I forgot to initialize the object. Now it works like a charm!