3

だから私はメソッドでこれを呼び出しています:

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

では、このエラーは何ですか?どうすれば修正できますか?

編集: この質問は解決されました。答えてくれてありがとう、私はこれを理解しようとして壁に頭をぶつけていました。ご希望であれば、数週間以内にリリースしたいと考えているので、アプリ内で言及することもできます。あなたの助けにより、コードの最大のバグが解決されました。再びありがとう!

4

3 に答える 3

8

-_fastCharacterContents:のプライベート メソッドですNSString。表示されるエラーは、対応するメッセージがインスタンスに送信されたNSURLため、クラッシュしたことを示しています。にurl渡されるパラメータ-initWithContentURL:NSURLではなく のようNSStringです。

配置する

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

メソッドの先頭にある . は、 の正確なクラスを示しているはずですurl

メソッドのシグネチャを次のように変更することをお勧めします。

- (void)initWithContentPath:(NSString *)path

メソッドが (相対) パスを表す文字列を想定していることを明確にするためです。Cocoa Touch には、引数 -initWithContentURL:を受け取ることを宣言する他のクラスがあります。NSURL *

于 2011-09-23T00:26:30.780 に答える
1

initWithContentURLをどのように呼び出していますか?NSStringに(不適切に)キャストされたNSURLを渡しているようです。

于 2011-09-23T00:32:25.293 に答える
1

ほとんどの場合、この種のエラーは、呼び出しで間違った型のオブジェクトを渡すことが原因です。

于 2011-09-23T00:27:54.997 に答える