应用程序崩溃 - [__ NSCFSet bytes]:无法识别的选择器发送到实例“”?

时间:2012-04-23 03:55:43

标签: iphone objective-c ipad

我正在开发一个应用程序,该应用程序对我有用,我的XCode版本是4.2.1,iOS版本是5.0 ARC启用代码。我的流程是使用网络服务在tableview中显示一堆YouTube视频。我将那些视频图标缓存在我的目录中。当我发送申请进行苹果审查时......应用程序在那里崩溃,崩溃报告正在跟踪,

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread:  2

特定应用信息:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFSet bytes]: unrecognized selector sent to instance 0x27b300'
*** First throw call stack:
(0x3502e88f 0x36455259 0x35031a9b 0x35030915 0x34f8b650 0x34f7da4d 0x3587f2b9 0x3587ef31 0x3587ee9d 0x321102ab 0x321101c7 0xe36dd 0x31053c59 0x3105f7bb 0x36cd9dfb 0x36cd9cd0)

Thread 2 name:  Dispatch queue: com.apple.root.default-priority
Thread 2 Crashed:

0   libsystem_kernel.dylib          0x34e2232c __pthread_kill + 8
1   libsystem_c.dylib               0x36d1e208 pthread_kill + 48
2   libsystem_c.dylib               0x36d17298 abort + 88
3   libc++abi.dylib                 0x309e3f64 abort_message + 40
4   libc++abi.dylib                 0x309e1346 _ZL17default_terminatev + 18
5   libobjc.A.dylib                 0x36455350 _objc_terminate + 140
6   libc++abi.dylib                 0x309e13be _ZL19safe_handler_callerPFvvE + 70
7   libc++abi.dylib                 0x309e144a std::terminate() + 14
8   libc++abi.dylib                 0x309e2798 __cxa_throw + 116
9   libobjc.A.dylib                 0x36455290 objc_exception_throw + 88
10  CoreFoundation                  0x35031a94 -[NSObject doesNotRecognizeSelector:] +   168
11  CoreFoundation                  0x3503090e ___forwarding___ + 294
12  CoreFoundation                  0x34f8b648 _CF_forwarding_prep_0 + 40
13  CoreFoundation                  0x34f7da46 CFDataGetBytePtr + 90
14  ImageIO                         0x3587f2b2 CGImageReadGetBytePointer + 30
15  ImageIO                         0x3587ef2a _CGImageSourceBindToPlugin + 86
16  ImageIO                         0x3587ee96 CGImageSourceGetCount + 50
17  UIKit                           0x321102a4 _UIImageRefFromData + 124
18  UIKit                           0x321101c0 -[UIImage initWithData:] + 52
19  MyAppName                   0x000e36d6 __37-[JMImageCache imageForURL:delegate:]_block_invoke_0 + 142
20  libdispatch.dylib               0x31053c52 _dispatch_call_block_and_release + 6
21  libdispatch.dylib               0x3105f7b4 _dispatch_worker_thread2 + 256
22  libsystem_c.dylib               0x36cd9df4 _pthread_wqthread + 288
23  libsystem_c.dylib               0x36cd9cc8 start_wqthread + 0

现在我的编码部分在申请中, 在表视图数据源方法

   if(![[JMImageCache sharedCache] isImageExistInCache: cell.videoThumbnailImageLink]){
    [cell.activityIndicator startAnimating];
    cell.videoThumbnail.image = [[JMImageCache sharedCache] imageForURL:cell.videoThumbnailImageLink delegate:cell];
}
else{
    [cell.activityIndicator stopAnimating];
    [cell.activityIndicator removeFromSuperview];
    cell.videoThumbnail.image = [[JMImageCache sharedCache] imageFromDiskForURL:cell.videoThumbnailImageLink];
}

在该tableview的自定义单元格中,

#pragma mark - JMImageCacheDelegate Methods
                                                                                               - (void) cache:(JMImageCache *)c didDownloadImage:(UIImage *)i forURL:(NSString *)url {
         if([url isEqualToString:self.videoThumbnailImageLink]) {
      self.imageView.image = i;
      [self setNeedsLayout];
}
    [self.activityIndicator stopAnimating];
[self.activityIndicator removeFromSuperview];

}

在JMImageCache库代码块中,

- (UIImage *) imageForURL:(NSString *)url delegate:(id<JMImageCacheDelegate>)d {
    if(!url) {
        return nil;
    }

    id returner = [super objectForKey:url];

    if(returner) {
        return returner;
    } else {
        UIImage *i = [self imageFromDiskForURL:url];

        if(i) {  
            [self setImage:i forURL:url];

            return i;
        }

        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            __unsafe_unretained NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
            UIImage *i = [[UIImage alloc] initWithData:data];

            __unsafe_unretained NSString* cachePath = cachePathForURL(url);
            NSInvocation* writeInvocation = [NSInvocation invocationWithMethodSignature:[self methodSignatureForSelector:@selector(writeData:toPath:)]];
            [writeInvocation setTarget:self];
            [writeInvocation setSelector:@selector(writeData:toPath:)];
            [writeInvocation setArgument:&data atIndex:2];
            [writeInvocation setArgument:&cachePath atIndex:3];

            [self performDiskWriteOperation:writeInvocation];
            [self setImage:i forURL:url];

            dispatch_async(dispatch_get_main_queue(), ^{
                if(d) {
                    if([d respondsToSelector:@selector(cache:didDownloadImage:forURL:)]) {
                        [d cache:self didDownloadImage:i forURL:url];
                    }
                }
            });
        });

        return nil;

    }
}

感谢。

2 个答案:

答案 0 :(得分:2)

你有记忆问题。提示是,指向内存中0x27b300的变量现在包含__NSCFSet(也称为NSSet)。确保您没有使用nil出现的变量或weak strong的变量。

答案 1 :(得分:1)

您的数据在使用之前正在被释放和释放,因此当CoreGraphics在其上调用-bytes时,它就不再存在(在这种情况下,已经在其位置分配了NSSet)。

据推测,这是因为您将其声明为__unsafe_unretained。