Xcode:ViewController 不显示 .view 或 addSubview:方法

发布于 2024-12-12 07:14:41 字数 842 浏览 0 评论 0原文

我创建了两个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑咖 2024-12-19 07:14:41

类和它的实例是不同的东西。

self.view 有效,因为类 PlayoutViewController 的实例具有 view 属性。

PlayoutViewController.view 没有,因为类对象本身没有这个属性。这同样适用于 TVOutViewController — 您应该调用一个实例,而不是类本身。

A class and its instances are different things.

self.view works, because instances of class PlayoutViewController have view 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.

知足的幸福 2024-12-19 07:14:41

到目前为止谢谢。

我的 TVOutViewController 是 UIViewController 的子类,如下所述:

@interface TVOutViewController : UIViewController {    }

我在 InterfaceBuilder 中向 TVOutViewController 添加了一个 UIView。我是否必须做其他事情才能做到类似:

[self.view addSubview: AnyUIView];

第二个问题:

如果我在 TVOutViewController.m 中声明一个方法,例如:

+(void)addSubviewMethod:(id)sender { [self.view addSubview: AnyUIView]; }

为什么我无法通过

[TVOutViewController addSubviewMethod];

添加

#import "TVOutViewController.h";

到 PlayOutViewController.m 在 PlayoutControlViewController.m 中调用它文件。

提前谢谢大家!

好的解决了:

你走在正确的轨道上:

我忘记初始化对象。现在它就像一个魅力!

TVOutViewController *MoviePlayerView = [[TVOutViewController alloc] init];
[MoviePlayerView.view addSubview:moviePlayer.view];

Thanks so far.

My TVOutViewController is a subclass of UIViewController, as described here:

@interface TVOutViewController : UIViewController {    }

I added a UIView to the TVOutViewController in InterfaceBuilder. Do I have to do something else to be able to do like:

[self.view addSubview: AnyUIView];

Second question:

If I declare a method in TVOutViewController.m, like:

+(void)addSubviewMethod:(id)sender { [self.view addSubview: AnyUIView]; }

Why am I not able to call it in the PlayoutControlViewController.m via

[TVOutViewController addSubviewMethod];

I added

#import "TVOutViewController.h";

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!

TVOutViewController *MoviePlayerView = [[TVOutViewController alloc] init];
[MoviePlayerView.view addSubview:moviePlayer.view];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文