2010-12-07 11 views
0
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Thread" inManagedObjectContext:managedObjectContext]; 

この行はもう機能していないようです(私はその行を確認しています)。XCode + iOS 4.2へのアップグレード後のコードデータの問題

私は問題を解決できないようです。アプリケーションは、iOS 4.1とXcodeの上で完全に働いたと今コンソールにこのエラーでクラッシュ:

2010-12-07 17:12:27.552 SMSApp[9222:207] +[ persistentStoreCoordinator]: unrecognized selector sent to class 0x5b14580 
2010-12-07 17:12:27.553 SMSApp[9222:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[ persistentStoreCoordinator]: unrecognized selector sent to class 0x5b14580' 
*** Call stack at first throw: 
(
    0 CoreFoundation      0x01547be9 __exceptionPreprocess + 185 
    1 libobjc.A.dylib      0x0169c5c2 objc_exception_throw + 47 
    2 CoreFoundation      0x015497bb +[NSObject(NSObject) doesNotRecognizeSelector:] + 187 
    3 CoreFoundation      0x014b9366 ___forwarding___ + 966 
    4 CoreFoundation      0x014b8f22 _CF_forwarding_prep_0 + 50 
    5 CoreData       0x00e6f3ca +[NSEntityDescription entityForName:inManagedObjectContext:] + 42 
    6 SMSApp        0x000046b9 -[MessagesRootViewController reloadMessages:] + 146 
    7 SMSApp        0x00004a09 -[MessagesRootViewController viewDidLoad] + 85 
    8 UIKit        0x0052265e -[UIViewController view] + 179 
    9 UIKit        0x00520a57 -[UIViewController contentScrollView] + 42 
    10 UIKit        0x00531201 -[UINavigationController _computeAndApplyScrollContentInsetDeltaForViewController:] + 48 
    11 UIKit        0x0052f831 -[UINavigationController _layoutViewController:] + 43 
    12 UIKit        0x00530b4c -[UINavigationController _startTransition:fromViewController:toViewController:] + 524 
    13 UIKit        0x0052b606 -[UINavigationController _startDeferredTransitionIfNeeded] + 266 
    14 UIKit        0x00643e01 -[UILayoutContainerView layoutSubviews] + 226 
    15 QuartzCore       0x010b4451 -[CALayer layoutSublayers] + 181 
    16 QuartzCore       0x010b417c CALayerLayoutIfNeeded + 220 
    17 QuartzCore       0x010ad37c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 310 
    18 QuartzCore       0x010ad0d0 _ZN2CA11Transaction6commitEv + 292 
    19 UIKit        0x0047719f -[UIApplication _reportAppLaunchFinished] + 39 
    20 UIKit        0x00477659 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 690 
    21 UIKit        0x00481db2 -[UIApplication handleEvent:withNewEvent:] + 1533 
    22 UIKit        0x0047a202 -[UIApplication sendEvent:] + 71 
    23 UIKit        0x0047f732 _UIApplicationHandleEvent + 7576 
    24 GraphicsServices     0x01b2ca36 PurpleEventCallback + 1550 
    25 CoreFoundation      0x01529064 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52 
    26 CoreFoundation      0x014896f7 __CFRunLoopDoSource1 + 215 
    27 CoreFoundation      0x01486983 __CFRunLoopRun + 979 
    28 CoreFoundation      0x01486240 CFRunLoopRunSpecific + 208 
    29 CoreFoundation      0x01486161 CFRunLoopRunInMode + 97 
    30 UIKit        0x00476fa8 -[UIApplication _run] + 636 
    31 UIKit        0x0048342e UIApplicationMain + 1160 
    32 SMSApp        0x000025c4 main + 102 
    33 SMSApp        0x00002555 start + 53 
) 
terminate called after throwing an instance of 'NSException' 

このエラーがから来ているか、それを引き起こしているものを任意のアイデアを?

iOS 4.2でXCodeにアップグレードすると、一部のファイルがプロジェクトから削除されました。私はなぜそれがあったのかわからない。なぜなら、ファイルがリンクされていて実際には私が夢中になっていないからだ。

アイデア?

おかげ

// EDIT

この方法は、AppDelegateである:

- (NSManagedObjectContext *)managedObjectContext { 

    if (managedObjectContext_ != nil) { 
     return managedObjectContext_; 
    } 

    NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; 
    if (coordinator != nil) { 
     managedObjectContext_ = [[NSManagedObjectContext alloc] init]; 
     [managedObjectContext_ setPersistentStoreCoordinator:coordinator]; 
    } 
    return managedObjectContext_; 
} 

// EDIT AGAIN

- (void)reloadMessages:(NSNotification *)notification { 
    NSLog(@"RECIEVED NEW MESSAGES TO MessagesRootViewController"); 

    NSLog(@"%@",managedObjectContext); 

    // we need to get the threads from the database... 
    NSFetchRequest *theReq = [[NSFetchRequest alloc] init]; 
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Thread" inManagedObjectContext:self.managedObjectContext]; 
    [theReq setEntity:entity]; 

    threads = [NSArray arrayWithArray:[managedObjectContext executeFetchRequest:theReq error:nil]]; 

    [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO]; 

    if(notification != nil){ // if its been caused by a notification 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"New Message" message:@"A new message has been received" delegate:nil cancelButtonTitle:@"Thanks" otherButtonTitles:nil]; 
     [alert performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO]; 
     [alert release]; 
    } 
} 

// EDIT 3

の場合私はthを入れますそれは正常に動作する私のアプリケーションデリゲートのapplicationDidFinishLoadingのコードです! ClassNameが定義されており、persistentStoreCoordinatorクラスメソッドを持っていることを確認します

[ClassName persistentStoreCoordinator] 

NSFetchRequest *theReq = [[NSFetchRequest alloc] init]; 
    NSEntityDescription *theEntity = [NSEntityDescription entityForName:@"Thread" inManagedObjectContext:self.managedObjectContext]; 
    [theReq setEntity:theEntity]; 

    NSArray *theThreads = [NSArray arrayWithArray:[self.managedObjectContext executeFetchRequest:theReq error:nil]]; 
+0

清掃してから再構築しましたか? –

+0

ソースファイルやその他のファイルはありますか? – BoltClock

+0

クリーンが動作しません。ボルトクルック:どういう意味ですか?削除されたファイルはソースファイルでした。 :) .hと.msですが、それらは私が輸入した別のフレームワークのものであり、いくつかはちょうどリンクされていました(もっとたくさんあると思いましたが、削除されたのは2つだけでした)。 –

答えて

1

あなたのコードをすばやく見た後、私は注意が必要な2つの部品を見つけたと思います。私が試してみて、以下にそれらを打破するでしょう:

SMSAppAppDelegate

1)自分のインターフェイスファイルに、変数名の末尾にアンダースコアを使用してCoreData変数を宣言していることに注意してください。その後、アンダースコアのを除いて、それぞれのivarのプロパティを作成します。このクラスでは、直接managedObjectContextを呼び出している)

@synthesize managedObjectContext=managedObjectContext_; 
@synthesize managedObjectModel=managedObjectModel_; 
@synthesize persistentStoreCoordinator=persistentStoreCoordinator_; 

DownloadContacts

1:それは限り、あなたは彼らがあなたの実装から欠落しているように見える正しい割り当てを、作る@synthesizeとして、すべての罰金です変数を介して。私はそれをお勧めしませんが、これはあなたの実際の問題ではありません。所有権がなくても、deallocでmanagedObjectContextを解放することに注意してください。

2)このケースでは、コンテキストのプロパティを宣言し、常にプロパティを介してにアクセスします。また、末尾にアンダースコアを含むようにインスタンス変数の名前を変更すると、直接アクセスする機会を最小限に抑えることができます(selfを使わずに)。このクラスのどこで実際にそれを行っているかを簡単に見つけることができますメモリからいくつかの場所があります)。お使いのインタフェースファイル中のSO

、managedObjectContextのIVARの名前を変更し、プロパティを宣言:

NSManagedObjectContext *managedObjectContext_; 
... 
@property (nonatomic, retain) NSManagedObjectContext managedObjectContext; 

そして、あなたが保持してプロパティを使用しているので、@sythesizeに割り当てを行うとのdeallocにリリースすることを忘れないでください:

@synthesize managedObjectContext=managedObjectContext_; 
... 
[managedObjectContext_ release]; 

次に、あなたがしようとすると、あなたが行くとself.managedObjectContext

にそれを変更する必要がどこである認識されていないインスタンス変数の2つのまたは3つのエラーを取得するコンパイルした場合

MessagesRootViewController

そして、あなたはあなたのMessagesRootViewControllerに同じプロセスを経るが、この1つはまだあるように正常に動作する必要があります最終的に私はお勧めします!

上記のいずれかが明確でない場合はどうすればいいのか教えてください。 乾杯、 Rog

+0

こんにちは。あなたの答えのステップ2については本当に確かではありませんが、上記の問題のあるコードでメソッドを貼り付けました。NSLoggedされているどこに出てくるmanagedObjectContextしかし、これはNSLogsがうまくいないinit関数で設定されています!retainを追加することは助けにはならないと思われますが、上の問題のあるメソッドでも設定しません:/ persistentStoreCoordinatorは、ありがとう:) –

+0

あなたはmanagedObjectContextをどのように初期化していますか?あなたが直接AppDelegateからリファレンスを取得していますか? AppDelegateのmanagedObjectContextメソッドを見ると、まずpersistentStoreCoordinator設定を呼び出す前にnilをチェックすることに気づくでしょう。 managedObjectContextを手動で初期化する場合、そのメソッドでnilが返されることはなく、persistentStoreCoordinatorは決して作成されません。カスタムゲッターが適切な初期化を行うためには、そのプロパティを介して常にコンテキストにアクセスしていることを確認する必要があります。 – Rog

+0

私のAppDelegateでは、myViewController.managedObjectContext = self.managedObjectContextでmanagedObjectContextへの参照を渡します。 self.managedObjectコンテキストにアクセスすることによって、persistentStoreCoordinator、オブジェクトモデル、永続ストアなどと一緒に正しく初期化されていることを確認しています。一度完了すると、コンテキストをユーザーに渡す必要があるため、参照を渡す必要があります。上記のようにNULLになることはありません。 – Rog

0

私はあなたのような何かをやっていると仮定しています。おそらく、これらのことを行ったファイルが削除されたでしょうか?

マット

+0

うーん...私は見ているよ。このプログラムは、特定のファイルを見つけることができないと不平を言うことはありませんが、あなたは何かの上にいるかもしれません。私は行くと見てみましょう。 :) –

+0

すべてのファイルを元のファイルに置き換えました。それらはすべてそこにあります。それでも動作しません。 : –

0

あなたのデータベースが壊れている可能性があり、iOSシミュレータをクリックしてのiOSシミュレータ をリセットしてください>コンテンツと設定をリセットします。

: 存在しないセレクタを呼び出そうとしているようです。実行時に見つからないメソッドがあるように見えるので、削除されたファイルを調べてみてください。コアデータクラスが消去されたのでしょうか?

+0

done ... not working –

関連する問題