eggfish
eggfish

Reputation: 65

Yet another - “Unrecognized Selector Sent to Instance” issue

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).

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).

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

enter image description here

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


Edit - in response to proposed answer containing IB comment

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

Edit - in response to question about valid SetPlayer

The view class in question looks like this:

 @class AVPlayer;

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

and impl:

 @implementation YOPlaybackView

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

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

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

 @end

Edit - output log

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)

Upvotes: 2

Views: 2078

Answers (2)

Felix Lamouroux
Felix Lamouroux

Reputation: 7494

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?

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

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

Upvotes: 1

eggfish
eggfish

Reputation: 65

Using @FelixLam's very helpful advice I managed to get more log output data, which is now inserted as the third edit in the question. The first line output states that the Interface Builder does not know what my custom view class was. With a bit of searching on the site I came across the answer to that problem here ("Unknown class <MyClass> in Interface Builder file" error at runtime) - which turns out to be the answer to my question as well.

In short, the linker flag "-ObjC" must be added to the project, which forces the linker to load the members of the class.

Upvotes: 0

Related Questions