0

私のアプリケーションでは、バーボタンを押したときにモーダルビューコントローラを表示する機能があります。時々、私は同じ関数をprogrmaticallyコールする必要があります。しかし、プログラムでビューを提示する必要があるときはいつでも、クラッシュします。私はこれがクラッシュするコード行であると判断しました。モーダルビューコントローラを表示するとクラッシュします

[self presentModalViewController:controller animated:YES]; 

そして私は私が私のエンティティに新しいオブジェクトを挿入するわけではないにもかかわらず、

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name 'Website'' 

エラーが発生します。

編集: ここでは、プログラムでボタンボタンを押したときに呼び出される関数を示します。

- (void) presentController { 
WebController *webController = [[WebController alloc] initWithNibName:@"WebController" bundle:nil]; 
webController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
webController.delegate = self; 
[self presentModalViewController:webController animated:YES]; 
[webController release]; 
} 

これはエラーが発生するコードです。

- (NSFetchedResultsController *)fetchedResultsController { 

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

/* 
Set up the fetched results controller. 
*/ 
// Create the fetch request for the entity. 
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; 
// Edit the entity name as appropriate. 
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Website" inManagedObjectContext:self.managedObjectContext]; 
[fetchRequest setEntity:entity]; 

// Set the batch size to a suitable number. 
[fetchRequest setFetchBatchSize:20]; 

// Edit the sort key as appropriate. 

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES]; 

NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil]; 

[fetchRequest setSortDescriptors:sortDescriptors]; 

// Edit the section name key path and cache name if appropriate. 
// nil for section name key path means "no sections". 
NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Root"]; 
aFetchedResultsController.delegate = self; 
self.fetchedResultsController = aFetchedResultsController; 

[aFetchedResultsController release]; 
[fetchRequest release]; 
[sortDescriptor release]; 
[sortDescriptors release]; 

NSError *error = nil; 
if (![fetchedResultsController_ performFetch:&error]) { 
    /* 
    Replace this implementation with code to handle the error appropriately. 

    abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button. 
    */ 
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
    abort(); 
} 

return fetchedResultsController_; 

}

編集:私のアプリケーションがバックグラウンド状態から再開したとき、私はappDelegateから機能presentControllerを呼び出していますので、私は私のViewControllerのviewDidLoad機能で同じ関数を呼び出す試みたが、それがクラッシュしません。

+0

エラーメッセージ全体を含める必要があります。 NSInternalInconsistencyExceptionは多くの可能性をカバーします。 – TechZen

+0

プログラムで呼び出すために使用するコードの詳細が必要です。この問題は、そのコードのどこかに隠されることになります。なぜなら、それは、それが働いているかどうかの違いだからです。 –

答えて

0

私はNSNotificationCenterを使って私のviewControllerにメッセージを送って、私のappDelegateから通知を送る際に働くpresentControllerというメソッドを呼び出すようにしました。

0

コントローラを提示する前にコントローラを初期化してもよろしいですか?

また、ペン先を使用している場合は、すべてのコンセントが正しく接続されていることを確認してください。

+0

私はそれをプログラマチックに呼び出すと常にクラッシュする点を除いて、バーボタンが押されたときに呼び出されるのとまったく同じ関数を呼び出しています。 – hd143

0

エラーメッセージの断片に基づいて、問題が含まれている行である:

+[NSEntityDescription entityForName:inManagedObjectContext:] 

...方法。

ほとんどの場合、フェッチ要求のエンティティを提供するエンティティを取得しました。

+0

エラーは、クラッシュ時にその行にあると言いますが、エラーは他のviewControllerを表示するviewControllerにあり、提示されているものではないため、なぜ表示されません。 – hd143

+0

証拠にあなたのロジックを課してはいけません。エラーはそれがどこにあるかです。あなたが少なくともそれを除外することができる前に発生するエラーとコードを理解する必要があります。いずれにしても、失敗した行の周りの実際のコードを見ることなく、あなたを助けることはできません。 – TechZen

+0

この行は何も挿入しませんが、代わりにモデルからエンティティの説明を取得します。エンティティが見つからないか、エンティティが重複してヒットしたり、その他の理由で失敗する可能性があります。 – TechZen

関連する問題