xcode 目标 c:无法识别的选择器发送到实例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4923473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 20:11:41  来源:igfitidea点击:

Objective c: unrecognized selector sent to instance

iphoneobjective-cxcodeinstanceunrecognized-selector

提问by Cornholio

I know this kind of question is repeatedly floating around over and over, but i haven't been able to solve my problem with any answer i found :( .

我知道这类问题一遍又一遍地反复出现,但我无法用我找到的任何答案解决我的问题:(。

I'm developing an application and i need to fetch audio stream. I decided to go with MPMoviePlayer, so i did this:

我正在开发一个应用程序,我需要获取音频流。我决定使用 MPMoviePlayer,所以我这样做了:

#import "MediaPlayer/MediaPlayer.h"    
@interface FirstViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
    ...     
    IBOutlet MPMoviePlayerViewController *theMovie;
    ...
}

...
@property (nonatomic, retain) MPMoviePlayerViewController *theMovie;

and in the implementation, i've just @synthesize-d it.

在实现中,我只是@synthesize-d 它。

And now, whenever I allocate it and try to access it's members or methods, I get this damn error unrecognized selector sent to instanceon the first line after the initialization:

现在,每当我分配它并尝试访问它的成员或方法时,我都会在初始化后的第一行收到这个该死的错误无法识别的选择器发送到实例

self.theMovie = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://netvarp.kringvarp.fo:554/radio/16/playlist.m3u8"]];
self.theMovie.moviePlayer.controlStyle = MPMovieControlStyleNone;       
    ...

(this is in viewDidLoad method).

(这是在 viewDidLoad 方法中)。

I get the error in this line:

我在这一行收到错误:

self.theMovie.moviePlayer.controlStyle = MPMovieControlStyleNone;

or whatever i call after the initialization.

或者我在初始化后调用的任何内容。

Same goes if I remove the IBOutlet, if i call it without 'self', if declare a MPMoviePlayerController. I can't figure out what i'm I doing wrong for 2 days! So embarrassing :(

如果我删除 IBOutlet,如果我在没有“self”的情况下调用它,如果声明一个MPMoviePlayerController 也是如此。我无法弄清楚我做错了什么 2 天!真难为情 :(

Any help will be appreciated.

任何帮助将不胜感激。

I forgot to mention, Target OS is > 3.0. Everything works okay on the simulator, but not on devices (iPhone 2G and iPhone 3G, both with IOS 3.1.3)

我忘了提,目标操作系统 > 3.0。在模拟器上一切正常,但在设备上不正常(iPhone 2G 和 iPhone 3G,都带有 IOS 3.1.3)

回答by WrightsCS

You will need to post the crash output. unrecognized selectormeans you are trying to call something that doesn't exist, for example:

您将需要发布崩溃输出。unrecognized selector意味着您正在尝试调用不存在的东西,例如:

[self doSomethingSpecial];

if doSomethingSpecialdoesn't exist in your controller, you will receive the unrecognized selector sent to instance

如果doSomethingSpecial您的控制器中不存在,您将收到发送到实例无法识别的选择器

回答by TuanCM

As the Apple Documentations says: controlStyle is only available in iOS 3.2 and later.

正如 Apple 文档所说: controlStyle 仅在 iOS 3.2 及更高版本中可用。

I think this could be your problem, since this method is not available on your 3.1.3 device, but It is on the simulator, I guess (4.2.1).

我认为这可能是你的问题,因为这个方法在你的 3.1.3 设备上不可用,但它在模拟器上,我猜(4.2.1)。