是什么 - [NSURL _fastCharacterContents] :?

Cod*_*aFi 3 init nsstring cfstring ipad ios

所以我在一个方法中调用它:

-(id)initWithContentURL:(NSString *)url {
if (self = [super init]) {
    NSLog(@"xSheetMusicViewController - %@",url);
    // Casting an NSString object pointer to a CFStringRef:
    CFStringRef cfString = (CFStringRef)url;        
    CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), cfString, NULL, NULL);
    pdf = CGPDFDocumentCreateWithURL((CFURLRef)pdfURL);
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

哪一个在NSLog的标记处发生了崩溃:

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), cfString, NULL, NULL);
Run Code Online (Sandbox Code Playgroud)

我从未见过这个奇妙的小错误.这是崩溃日志:

SheetMuse[83550:b603] -[NSURL _fastCharacterContents]: unrecognized selector sent to instance 0x4ec35f0
2011-09-22 17:36:22.921 SheetMuse[83550:b603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL _fastCharacterContents]: unrecognized selector sent to instance 0x4ec35f0'
*** Call stack at first throw:
(
0   CoreFoundation                      0x011be5a9 __exceptionPreprocess + 185
1   libobjc.A.dylib                     0x01312313 objc_exception_throw + 44
2   CoreFoundation                      0x011c00bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3   CoreFoundation                      0x0112f966 ___forwarding___ + 966
4   CoreFoundation                      0x0112f522 _CF_forwarding_prep_0 + 50
5   CoreFoundation                      0x010d2857 CFStringGetCharactersPtr + 135
6   CoreFoundation                      0x010d6c93 CFStringGetFileSystemRepresentation + 35
7   CoreFoundation                      0x01110811 _CFFindBundleResources + 289
8   CoreFoundation                      0x0110d961 CFBundleCopyResourceURL + 305
9   SheetMuse                           0x00005b19 -[xSheetMusicViewController initWithContentURL:] + 153
10  SheetMuse                           0x00009724 -[ExamplesViewController tableView:didSelectRowAtIndexPath:] + 708
11  UIKit                               0x00487b68 -[UITableView _selectRowAtIndexPath:animated:scrollPosition:notifyDelegate:] + 1140
12  UIKit                               0x0047db05 -[UITableView _userSelectRowAtPendingSelectionIndexPath:] + 219
13  Foundation                          0x00b9779e __NSFireDelayedPerform + 441
14  CoreFoundation                      0x0119f8c3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19
15  CoreFoundation                      0x011a0e74 __CFRunLoopDoTimer + 1220
16  CoreFoundation                      0x010fd2c9 __CFRunLoopRun + 1817
17  CoreFoundation                      0x010fc840 CFRunLoopRunSpecific + 208
18  CoreFoundation                      0x010fc761 CFRunLoopRunInMode + 97
19  GraphicsServices                    0x028a31c4 GSEventRunModal + 217
20  GraphicsServices                    0x028a3289 GSEventRun + 115
21  UIKit                               0x0041ec93 UIApplicationMain + 1160
22  SheetMuse                           0x000028a9 main + 121
23  SheetMuse                           0x00002825 start + 53
)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
Run Code Online (Sandbox Code Playgroud)

那么,这个错误是什么,我该如何解决?

编辑:这个问题已经解决了.谢谢大家的回答,我正试着弄清楚我的想法.如果您愿意,我可以在应用程序中提及您,看到我想在几周内发布它,并且您的帮助已经解决了代码中的最大错误.再次谢谢你!

小智 9

-_fastCharacterContents:是一种私人方法NSString.您收到的错误表明相应的消息正在发送到NSURL实例,因此崩溃.它看起来像url传递给的参数-initWithContentURL:NSURL,而不是NSString.

配售

NSLog(@"url is of type %@", [url class]);
Run Code Online (Sandbox Code Playgroud)

在方法的开头应该告诉你确切的类url.

我建议你将方法签名改为:

- (void)initWithContentPath:(NSString *)path
Run Code Online (Sandbox Code Playgroud)

为了清楚表明该方法需要一个表示(相对)路径的字符串.Cocoa Touch中还有其他类声明 -initWithContentURL:接收NSURL *参数.