2011-09-22 26 views
3

所以我的方法調用此:什麼是 - [NSURL _fastCharacterContents]:?

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

那麼,這是什麼錯誤,以及如何解決它?

編輯:這個問題已經解決了。謝謝大家的回答,我正在試圖弄清楚這個問題。如果你願意,我可以在應用中提及你,看到我想在幾周內發佈它,並且你的幫助已經消除了代碼中最大的錯誤。再次謝謝你!

回答

9

-_fastCharacterContents:NSString的私有方法。您收到的錯誤表示相應的消息正在發送到一個NSURL實例,因此發生崩潰。它看起來像url參數傳遞到-initWithContentURL:NSURL,而不是NSString

在方法的開始配售

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

應該告訴你確切的類url

我建議你改變你的方法簽名:爲了說清楚,該方法需要代表一個(相對)路徑的字符串

- (void)initWithContentPath:(NSString *)path 

。 Cocoa Touch中還有其他類,聲明 -initWithContentURL:接收NSURL *參數。

+0

其實,你是完全正確的! NSLog返回「是NSURL類型」。非常感謝! – CodaFi

+0

另外,檢查編輯,我想在你做任何事情之前表達你的許可。 – CodaFi

+0

@Cod我寧可不要。 Upvoting就足夠了。 :) – 2011-09-23 13:00:07

1

在大多數情況下,這種錯誤是由於在調用中傳遞錯誤類型的對象造成的。

1

你是怎麼調用initWithContentURL的?看起來你可能會傳遞一個已經(不正確)轉換爲NSString的NSURL。