【问题标题】:Xcode: ViewController shows no .view or addSubview: methodsXcode: ViewController 没有显示 .view 或 addSubview: 方法
【发布时间】:2011-10-28 14:02:02
【问题描述】:

我创建了两个 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

抱歉,我知道错误的含义,但不知道如何修复它们。

提前致谢!

附:我在 PlayoutViewController.m 中,其中:

[self.view addSubview: (anyUIView)];
//works

//and

[PlayoutViewController.view addSubview: (anyUIView)];
//won't work.

...谢谢!

【问题讨论】:

    标签: xcode uiviewcontroller media-player subview


    【解决方案1】:

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

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

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

    【讨论】:

    • 感谢您的贡献。您能否为我举例说明如何调用这些实例?谢谢!
    • @Darwin 与您调用self 实例的方式相同。您是如何创建 TVOutViewController 类型的对象的?
    【解决方案2】:

    到目前为止谢谢。

    我的 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];
    

    【讨论】:

      猜你喜欢
      • 2021-06-03
      • 2018-04-27
      • 1970-01-01
      • 2014-12-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-27
      相关资源
      最近更新 更多