另一个-“无法识别的选择器已发送至实例"问题 [英] Yet another - “Unrecognized Selector Sent to Instance” issue

查看:90
本文介绍了另一个-“无法识别的选择器已发送至实例"问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查看了有关此主题的每个问题,但没有一个给我解决方案. 我的项目在很大程度上复制了开发库中的AVPlayer演示应用程序(减去了清理功能):我有一个复制并粘贴AVPlayerDemoPlaybackView类(重命名为YOPlaybackView)和一个关联的控制器,以及一个非常相似的xib(减去洗涤塔). 我的视图控制器代码非常接近演示中的模式(为简洁起见,下面仅发布了代码差异).

I've looked at each posted question on this topic, but none give me a solution. My project replicates to a large extent the AVPlayer demo app in the dev library (minus the scrubbing capabilities): I have a copy and paste AVPlayerDemoPlaybackView class (renamed YOPlaybackView) and an associated controller, along with a very similar xib (minus the scrubber). My view controller code follows very closely the pattern in the demo (code differences only posted below for brevity).

  • 我已确保视图控制器是文件的所有者
  • 我确保商店没有重复
  • 我已经通过在dealloc

当播放器的当前项目更改/将更改时,在observeValueForKeyPath方法中发生错误.下面的行给出了错误-[UIView SetPlayer:]":无法识别的选择器已发送到实例..."

The error occurs in the observeValueForKeyPath method when the current item for the player changes/will change. The following line gives the error "-[UIView SetPlayer:]": unrecognised selector sent to instance ..."

    [playbackView setPlayer:player];

如果在此调用之前创建该视图的实例,则不会收到错误消息:

If I create an instance of that view just prior to this call, I don't get the error:

        YOPlaybackView* vw = [[YOPlaybackView alloc] init];
        [playbackView setPlayer:player];

在我看来,这可能与笔尖延迟加载(创建实例使它栩栩如生)有关.

It seems to me that it might be something to do with nib lazy loading (and creating an instance kicks it in to life).

在调试器窗口中查看,无论有没有创建(未使用)实例的额外行,playbackView似乎都是有效的.

Looking in the debugger window, playbackView seems to be valid with and without the extra line that creates an (unused) instance.

任何人都可以帮助提高我的对象/应用程序生命周期知识吗?

Can anyone help progress my object/app lifecycle knowledge please?

编辑-针对包含IB评论的建议答案

这是IB的快照,显示了视图层次结构,并在检查器中正确命名了自定义视图.

This is a snap of the IB, showing the view hierarchy and correctly named custom view in the inspector.

编辑-回答有关有效SetPlayer的问题

有问题的视图类如下:

 @class AVPlayer;

 @interface YOPlaybackView : UIView
 @property (nonatomic, retain) AVPlayer* player;
 - (void)setPlayer:(AVPlayer*)player;
 @end

和隐含:

 @implementation YOPlaybackView

 + (Class)layerClass
 {
   return [AVPlayerLayer class];
 }

 - (AVPlayer*)player
 {
   return [(AVPlayerLayer*)[self layer] player];
 }

 - (void)setPlayer:(AVPlayer*)player
 {
   [(AVPlayerLayer*)[self layer] setPlayer:player];
 }

 @end

编辑-输出日志

2013-07-23 12:05:39.084 iOSVideoPlayerExample[8331:14003] Unknown class YOPlaybackView in Interface Builder file.
2013-07-23 12:05:39.956 iOSVideoPlayerExample[8331:14003] Unbalanced calls to begin/end appearance transitions for <YOMasterViewController: 0x985aa10>.
2013-07-23 12:05:40.428 iOSVideoPlayerExample[8331:14003] <UIView: 0x8383900; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x8381710>>
2013-07-23 12:05:40.429 iOSVideoPlayerExample[8331:14003] -[UIView setPlayer:]: unrecognized selector sent to instance 0x8383900
(lldb)

推荐答案

您的playbackView似乎是UIView的实例,该实例没有名为setPlayer:的方法.检查您是否正在创建自己的UIView子类的实例.您可以在创建playbackView的地方粘贴代码段吗?

Your playbackView appears to be an instance of UIView which does not have a method called setPlayer:. Check that you are creating an instance of your own subclass of UIView. Could you post the snippet of code where you create the playbackView?

如果使用的是Interface Builder,请确保已在检查器中设置了正确的类.

If you are using Interface Builder make sure that you have set the correct class in the inspector.

您将需要在代码中的某处引用该类.尝试在setPlayer:调用的正上方添加[YOPlaybackView class].

You will need to reference the class somewhere in your code. Try Adding [YOPlaybackView class] right above the setPlayer: call.

这篇关于另一个-“无法识别的选择器已发送至实例"问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆