【问题标题】:What Is -[NSURL _fastCharacterContents]:?什么是 -[NSURL _fastCharacterContents]:?
【发布时间】:2011-09-22 23:42:04
【问题描述】:

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

-(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;
}

在标记行的 NSLog 处崩溃:

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), cfString, NULL, NULL);

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

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

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

编辑:这个问题已经解决了。谢谢所有回答的人,我正在努力解决这个问题。如果您愿意,我可以在应用程序中提及您,因为我想在几周内发布它,您的帮助已经解决了代码中最大的错误。再次感谢您!

【问题讨论】:

    标签: ios ipad nsstring init cfstring


    【解决方案1】:

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

    放置

    NSLog(@"url is of type %@", [url class]);
    

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

    我建议您将方法签名更改为:

    - (void)initWithContentPath:(NSString *)path
    

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

    【讨论】:

    • 其实你完全正确!返回的 NSLog “属于 NSURL 类型”。非常感谢!
    • 另外,检查编辑,在我做任何事情之前我需要你的明确许可。
    • @Cod 我宁愿不要。点赞就够了。 :)
    • 好的,再次感谢!附言我需要调用 stringWithString 才能让它工作。
    【解决方案2】:

    在大多数情况下,这种错误是由于在调用中传递了错误类型的对象。

    【讨论】:

      【解决方案3】:

      你是如何调用 initWithContentURL 的?看起来您可能正在传递一个已(不正确)转换为 NSString 的 NSURL。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-17
        • 2012-06-03
        • 2012-12-28
        • 2012-05-01
        • 1970-01-01
        • 2013-04-12
        • 1970-01-01
        相关资源
        最近更新 更多