Objective-Cを学び始めたので、私はこれを手助けするために「Head First iPhone Development」を使用しています。今私はSQLiteデータベースについて学習しており、これらを動作させるためには、SQLiteファイルをアプリケーションのDocumentsフォルダに置く必要があるため、ファイルを移動する必要があると言われています。SQLiteをある場所から別の場所に移動する:アプリケーションがクラッシュし、互換性のないタイプ
私は本の例を使用していますが、動作させることができません。コンパイルするたびに、アプリがクラッシュします。初期化「互換性のないObjective-Cのタイプ '構造体NSURLを*'、期待
'NSStringの*ストラクト' を誰もがこの問題を解決する方法の先端を持っています
EDIT:私は、次の警告がありますか?
NSURLを返すapplicationDocumentsDirectoryの2つの行に問題があるようですが、NSStringを返すように指示します。NSURLを返すように指示できますが、stringByAppendingPathComponentを使用する次の行で問題が発生します。これを修正する方法は?
NSString *documentsDirectory = [self applicationDocumentsDirectory];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"iBountyHunter.sqlite"];
これはどのようなデバッガコンソール出力時にアプリがクラッシュです:
2011-02-04 07:33:42.126 iBountyHunter[591:207] -[NSURL stringByAppendingPathComponent:]: unrecognized selector sent to instance 0x6043f80
2011-02-04 07:33:42.128 iBountyHunter[591:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL stringByAppendingPathComponent:]: unrecognized selector sent to instance 0x6043f80'
*** Call stack at first throw:
(
0 CoreFoundation 0x00f87be9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x010dc5c2 objc_exception_throw + 47
2 CoreFoundation 0x00f896fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x00ef9366 ___forwarding___ + 966
4 CoreFoundation 0x00ef8f22 _CF_forwarding_prep_0 + 50
5 iBountyHunter 0x00001d8e -[iBountyHunterAppDelegate createEditableCopyOfDatabaseIfNeeded] + 107
6 iBountyHunter 0x00001f24 -[iBountyHunterAppDelegate application:didFinishLaunchingWithOptions:] + 37
7 UIKit 0x002ba1fa -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1163
8 UIKit 0x002bc55e -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 439
9 UIKit 0x002c6db2 -[UIApplication handleEvent:withNewEvent:] + 1533
10 UIKit 0x002bf202 -[UIApplication sendEvent:] + 71
11 UIKit 0x002c4732 _UIApplicationHandleEvent + 7576
12 GraphicsServices 0x018bda36 PurpleEventCallback + 1550
13 CoreFoundation 0x00f69064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
14 CoreFoundation 0x00ec96f7 __CFRunLoopDoSource1 + 215
15 CoreFoundation 0x00ec6983 __CFRunLoopRun + 979
16 CoreFoundation 0x00ec6240 CFRunLoopRunSpecific + 208
17 CoreFoundation 0x00ec6161 CFRunLoopRunInMode + 97
18 UIKit 0x002bbfa8 -[UIApplication _run] + 636
19 UIKit 0x002c842e UIApplicationMain + 1160
20 iBountyHunter 0x00001cf8 main + 102
21 iBountyHunter 0x00001c89 start + 53
)
terminate called after throwing an instance of 'NSException'
私はあなたの最初のコードを試しましたが、動作させることはできません。ファイルがすでに存在しているため、移動されていないと思っていますが、TableViewに表示されるデータはありません。他のバージョンのapplicationDocumentsDirectoryメソッドを実装するにはどうすればよいですか? – simonbs
コードは私のアプリで動作します。 nslogを実行して、実際にdbにあるものを確認します。他のバージョンを使用するには、applicationDocumentsDirectory宣言を見つけてメソッドシグネチャを '+(NSSString *)'に変更し、コードを実装ファイルにコピーします。それでも自分自身で呼びたい場合は、+をaに変更する必要があります。クラスメソッドではなくインスタンスメソッドですが、 '[iBountyHunterAppDelegate applicationDocumentsDirectory] 'に変更しない理由はありません。 – Rich
私は推測します目的の基礎に慣れていないので、テーブルビューに何も表示させないメモリ管理上の問題があると思われます。テーブルビューの優れたリソースは次のとおりです:http://code.google.com/p/iphone4/downloads/listこれは「Advanced iOS 4 Programming」と呼ばれる本当に良い本のソースコードです。 「Head First iPhone Development」に問題がある場合は、別の本を購入することを検討することがあります。テーブルビューのもう1つの優れた点は、「もっとiPhone 3の開発:iPhone SDKに取り組む」(やや高密度ですが)です。 – Rich