0

クイック質問... IBActionボタンは新しいオブジェクトを作成していますが、ナビゲータがDetailViewControllerをプッシュするとSIGABRTが表示されます。 ここで私はちょうどそこにナビゲーションコントローラ機能を使用できないのだろうかと思っています。 次のコードは、私は、セルを選択するとDetailViewControllerが新しいオブジェクトの作成時に表示されない

- (IBAction)insertNewObject 
{ 
// Create a new instance of the entity managed by the fetched results controller. 
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext]; 
NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity]; 

Event *newEvent = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context]; 
DetailViewController *detailController = [[[DetailViewController alloc] init] autorelease]; 

[newEvent setValue:[NSDate date] forKey:@"timeStamp"]; 

// Save the context with the new object. 
NSError *error = nil; 
if (![context save:&error]) { 
    //improve this 
    NSLog(@"Unresolved error %@, %@", error, [error userInfo]); 
    abort(); 
} 

[detailController setEvent:newEvent]; 

NSLog(@"Detail Controller New Event 1 (from Master) : %@", newEvent); 

[self.navigationController pushViewController:detailController animated:YES]; 
} 

は、今では完璧に動作し正常に動作していないものです。したがって、以下のコードが動作します:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
if ([[segue identifier] isEqualToString:@"selectSegue"]) { 
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 

    Event *event = (Event *)[fetchedResultsController objectAtIndexPath:indexPath]; 
    NSLog(@"Event on Master:: %@", event); 

    DetailViewController *detailvc = [[[DetailViewController alloc] init] autorelease]; 

    detailvc.event = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
    NSLog(@"Event on Detail when created :: %@", detailvc.event); 

    if (event) [[segue destinationViewController] setEvent:(Event *) [self.fetchedResultsController objectAtIndexPath:indexPath]]; //was: setDetailItem:selectedObject 
    [event release]; 
    [detailvc.event retain]; 

} 
} 

私は何かがシンプルに欠けているような感じです。しかし誰も私がSIGABRTを取得せずにそのDetailViewControllerにオブジェクトを追加するのを助けることができますか? ありがとう、新年あけましておめでとうございます。

答えて

0

コードは問題ありません。 私の経験では、エンティティにすべての必須属性を設定するかどうかを確認する必要があります。いくつかのケースでは、Error文はこのエラーに気付かないからです!

+0

すべての属性はオプションとマークされています。私はストーリーボードが私を混乱させていると思う。ビューコントローラを押す方法はたくさんあります。しかし、これまであなたの助けてくれてありがとう。 – Farini

関連する問題