Objective-c中[signal sigabrt]问题

xee 发布于 2014/10/31 10:42
阅读 2K+
收藏 0

代码运行后出现下面的问题。

2014-10-30 23:18:45.673 L6-4Another[73662:2444037] -[Dog updateFromPath:]: unrecognized selector sent to instance 0x100409e40

2014-10-30 23:18:45.676 L6-4Another[73662:2444037] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Dog updateFromPath:]: unrecognized selector sent to instance 0x100409e40'

*** First throw call stack:

(

0   CoreFoundation                      0x00007fff91e1464c __exceptionPreprocess + 172

1   libobjc.A.dylib                     0x00007fff866556de objc_exception_throw + 43

2   CoreFoundation                      0x00007fff91e176bd -[NSObject(NSObject) doesNotRecognizeSelector:] + 205

3   CoreFoundation                      0x00007fff91d5ea84 ___forwarding___ + 1028

4   CoreFoundation                      0x00007fff91d5e5f8 _CF_forwarding_prep_0 + 120

5   Foundation                          0x00007fff900cb023 __NSFireTimer + 95

6   CoreFoundation                      0x00007fff91d67b44 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20

7   CoreFoundation                      0x00007fff91d677d3 __CFRunLoopDoTimer + 1059

8   CoreFoundation                      0x00007fff91ddad9d __CFRunLoopDoTimers + 301

9   CoreFoundation                      0x00007fff91d24268 __CFRunLoopRun + 2024

10  CoreFoundation                      0x00007fff91d23838 CFRunLoopRunSpecific + 296

11  Foundation                          0x00007fff900ceab9 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 278

12  Foundation                          0x00007fff901ca45f -[NSRunLoop(NSRunLoop) run] + 74

13  L6-4Another                         0x0000000100001d2f main + 223

14  libdyld.dylib                       0x00007fff8fefc5c9 start + 1

15  ???                                 0x0000000000000001 0x0 + 1

)

libc++abi.dylib: terminating with uncaught exception of type NSException

(lldb) 


main.m


#import <Foundation/Foundation.h>
#import "Person.h"
#import "Dog.h"
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        Person * xee = [[Person alloc] init];
        Dog * dog =[[Dog alloc] init];
        [dog setID:10];
        [xee setDog:dog];
        
        while (1) {
            [[NSRunLoop currentRunLoop] run];
        }
        
    }
    return 0;
}



Dog.h
@interface Dog : NSObject

{
    int _ID;
    NSTimer * timer;
    int barkCount;
    
    void (^BarkCallback)(Dog *thisDog, int count);
    //定义一个blocks变量

}
@property (assign) int ID;

-(void)setBark:(void (^)(Dog *thisDog, int count))eachBark;
//向外暴露一个函数 setBark:
@end



Dog.m

#import "Dog.h"

@implementation Dog

@synthesize ID = _ID;

- (id)init
{
        if (self) {
        timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateFromPath:) userInfo:nil repeats:YES];
            //每隔1秒调用 [self updatTimer:nil]方法
    }
    return self;
}
- (void) updateTimer :(id)arg
    {
        barkCount ++;
        NSLog(@"Dog %d bark count %d",_ID, barkCount);
        if (BarkCallback) {
            BarkCallback(self,barkCount);
            //调用从person传过来的blocks
        }
    }

-(void)setBark:(void (^)(Dog *thisDog, int count))eachBark
{
    BarkCallback = [eachBark copy];
}
@end



Person.h

#import <Foundation/Foundation.h>
#import "Dog.h"
@interface Person : NSObject
{
    Dog * _dog;
}
@property (retain) Dog * dog;
@end



Person.m

#import "Person.h"

@implementation Person
@synthesize dog = _dog;

-(void)setDog:(Dog *)dog
{
    if(_dog != dog){
        [_dog setBark:^(Dog *thisDog, int count) {
            NSLog(@"person dog %d count %d",[thisDog ID],count);
        }];
        
    }
}
-(Dog *)dog
{
    return _dog;
}
@end



希望能够得到大家的帮助,指点一下问题出在哪里。万分感谢!



加载中
0
南山下
南山下
[Dog updateFromPath:]: unrecognized selector sent to instance 0x100409e40
提示这么明显了
0
南山下
南山下
你这个方法没有实现
南山下
南山下
@xee 不谢~周末没看到
xee
xee
@xee 已经解决了。找到了 谢谢
xee
xee
这个错误。具体是出现在哪句代码?哪段代码内存设置错误?
xee
xee
感谢您的帮助!
返回顶部
顶部