IOS核心数据错误

时间:2014-08-04 02:19:43

标签: ios xcode sqlite core-data

我做了一个将可变数组存储到sqlite数据库的测试项目,但它在save方法上显示错误

  

是无法识别的选择器,发送到实例0x8e688c0   地址保存目录对象的地方

#import "testViewController.h"


@end

@implementation testViewController

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"CatalogsList"       inManagedObjectContext:self.managedObjectContext];
    [fetchRequest setEntity:entity];
    NSError *error;
    NSArray* foundObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
    if([foundObjects count]>0){
        self.l = [foundObjects objectAtIndex:0];

        NSLog(@"found:size of list is %d",[self.l.list count]);

    }else{
        self.l = [NSEntityDescription insertNewObjectForEntityForName:@"CatelogsList" inManagedObjectContext:self.managedObjectContext];

        self.l.list = [[NSMutableArray alloc] initWithCapacity:20];
        NSLog(@"not found:size of list:%d",[self.l.list count]);

        //[self.managedObjectContext save:nil];

    }

    self.textField.delegate=self;
    self.catelogText.delegate=self;

}



  - (void)didReceiveMemoryWarning
 {
    [super didReceiveMemoryWarning];
   // Dispose of any resources that can be recreated.
 }

-(IBAction)addCatalog
{
    NSString* next name = self.catalogText.text;
    Catalog* newCatelog = [[Catelog alloc] init];
    newCatalog.name = nextname;
   // newCatalog.texts = [[NSMutableArray alloc] initWithCapacity:20];
    [self.l.list addObject:newCatalog];
    current = newCatalog;

    NSError* error;
    NSLog(@"saving");

    if(![self.managedObjectContext save:&error]){
        NSLog(@"core data failure:%@",error);
        abort();

    }


    NSLog(@"saved size of list is %d",[self.l.list count]);
 }



-(IBAction)show{
    NSLog(@"showing");
    if(self.l.list!=nil){

       for(Catalog* c in self.l.list){
        NSLog(@"Catalog:%@",c.name);        
        }

      }
   }

@end

CataLogsList.h文件:

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>


@interface CatalogsList : NSManagedObject

@property (nonatomic, retain) NSMutableArray* list;

@end

CataLogsList.m文件:

  #import "CatalogsList.h"


@implementation CatalogsList
@dynamic list;

@end

Catalog.h文件:

#import <Foundation/Foundation.h>

@interface Catelog : NSObject
@property(nonatomic,strong) NSString* name;
@end



enter code here

0 个答案:

没有答案