Coredata插入 - 没有堆栈跟踪的崩溃

时间:2014-05-08 04:48:53

标签: objective-c core-data

您好我正在尝试使用核心数据来使用核心数据插入数据。我还没有能够保存我的数据。正如我的代码现在所说的那样,程序在没有堆栈跟踪的情况下崩溃,所以我有点卡住了

detailedViewController代码

-(void) addobject{
    if(self.isEditing == false){
        MasterViewController *mvc = self.delegate;
        mvc.managedObjectContext = self.managedObjectContext;
        [mvc insertNewObject: self.txtUrlAddress.text : self.txtUrlName.text :     
        self.txtUrlImage.text];
     }
}

MasterViewController代码

-(void)insertNewObject: (NSString *) url : (NSString*) urlName : (NSString *) urlImage
{
    NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];

    NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
    Event *urlDatabase = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
    urlDatabase.url = url;
    urlDatabase.urlname = urlName;
    urlDatabase.urlImage = urlImage;
    // If appropriate, configure the new managed object.
    // Normally you should use accessor methods, but using KVC here avoids the need to add a custom class to the template.
    //[urlDatabase setValue:[NSDate date] forKey:@"urlname"];

    // Save the context.
    NSError *error = nil;
    if (![context save:&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. 
        NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
        abort();
    }
    int count = [[self.fetchedResultsController sections] count];
    NSLog([NSString stringWithFormat:@"Data base size is %d", count]);

}

任何人都可以看到我的代码的问题吗?

1 个答案:

答案 0 :(得分:0)

而不是

-(void)insertNewObject: (NSString *) url : (NSString*) urlName : (NSString *) urlImage

你应该写

-(void)insertNewObject:(NSString *) url urlName: (NSString*) urlName urlImage: (NSString *) urlImage

其余看起来很好我觉得..解决了这个问题吗?