0

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

[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_;

}

編集:presentControllerアプリケーションがバックグラウンド状態から再開したときにappDelegateから関数を呼び出しているので、viewControllerのviewDidLoad関数で同じ関数を呼び出そうとしましたが、クラッシュしません。

4

3 に答える 3

0

コントローラを提示する前に、コントローラを初期化していることを確認しますか?

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

于 2011-07-23T04:09:46.683 に答える
0

エラーメッセージの断片に基づくと、問題は次の内容を含む行にあります。

+[NSEntityDescription entityForName:inManagedObjectContext:]

... 方法。

ほとんどの場合、フェッチ要求にエンティティを提供するようにエンティティを取得した可能性があります。

于 2011-07-23T13:18:50.070 に答える
0

を使用NSNotificationCenterしてviewControllerにメッセージを送信し、appDelegateからpresentController通知を送信するときに機能するメソッドを呼び出すように指示しました。

于 2011-07-24T01:32:38.140 に答える