我用这个作为观察员:
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(newConnection:)
name:NSFileHandleConnectionAcceptedNotification
object:nil];但是,当应用程序崩溃时,它确实会被调用。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CALayerArray newConnection:]: unrecognized selector sent to instance 0x76aed70'这是当前为空的newConnection处理程序:
- (void)newConnection:(NSNotification*)notification
{
}它也在.h文件中正确声明.
这是调用通知的代码
socketPort = [[NSSocketPort alloc] initWithTCPPort:portNumber];
int fd = [socketPort socket];
fileHandle = [[NSFileHandle alloc] initWithFileDescriptor:fd
closeOnDealloc:YES];
...
[fileHandle acceptConnectionInBackgroundAndNotify];编辑:上面的内容是在我做的一堂课上做的。除了newConnection之外,所有东西都在这个函数中:
- (id)initWithPortNumber:(int)pn delegate:(id)dl
{
if( self = [super init] ) {
...
}我在viewController中这样调用了这个文件:
SimpleHTTPServer *server= [[SimpleHTTPServer alloc]initWithPortNumber:80 delegate:self];解决方案:
问题是:由于电弧系统,视图被取消了。
fileHandle acceptConnectionInBackgroundAndNotify;实际上并不是一个被检测到的循环,它将视图视为空闲并自动释放它,所以我只是做了一个小定时器,每秒钟运行一个循环,从而导致一个空方法。修复了它。
发布于 2013-08-30 07:54:00
问题是:由于弧形系统fileHandle acceptConnectionInBackgroundAndNotify,视图被解除了;实际上不是一个循环,它检测到视图时将视图视为空闲并自动释放它,所以我只是做了一个小计时器,每秒钟运行一个循环,从而导致一个空方法。修复了它。
发布于 2013-08-25 13:50:42
它确切地告诉您错误是什么:'NSInvalidArgumentException', reason: '-[CALayerArray newConnection:]: unrecognized selector sent to instance 0x76aed70'。
您需要问的问题是“为什么0x76aed70的对象是CALayerArray?”
从涵盖基本知识开始。在addObserver:…上设置一个断点,确保self是您所认为的那样。然后设置指针的轨道,以便调试器在其值被更改时中断。你应该能很快追踪到这一点。
我猜您的对象已被取消分配,而您没有移除观察者。
https://stackoverflow.com/questions/18428948
复制相似问题