在基于Core Data文档的应用程序中加载默认数据

时间:2012-11-10 13:49:40

标签: macos core-data nsfilemanager nsdocument

我有一个基于文档的应用程序,我希望在创建新文件时,tableview预先填充了默认数据。 我做了以下事情:

  1. 我启动了我的应用程序并填充了表格,然后保存了文件Untitled.sqlite
  2. 我在应用程序的资源
  3. 之间导入了文件Untitled.sqlite
  4. 我在以下文件中插入了以下代码
  5. MyApplicationDocumente.m:

    - (id)init {
    self = [super init];
    if (self) {
        // Add your subclass-specific initialization here.
        NSFileManager *fileManager = [NSFileManager defaultManager];
        if (![fileManager fileExistsAtPath:@"/Users/andreabollini/Library/Developer/Xcode/DerivedData/Preventivi-euqsrtroavapbwfjvljrxamywbvf/Build/Products/Debug/Preventivi.app/Contents/Resources/en.lproj"]) {
            NSString *defaultStorePath = [[NSBundle mainBundle]
                                          pathForResource:@"Untitled" ofType:@"sqlite"];
    
            if (defaultStorePath) {
                [fileManager copyItemAtPath:defaultStorePath toPath:@"/Users/andreabollini/Library/Developer/Xcode/DerivedData/Preventivi-euqsrtroavapbwfjvljrxamywbvf/Build/Products/Debug/Preventivi.app/Contents/Resources/en.lproj" error:NULL];
                [tabella1 reloadData];
                [tabella2 reloadData];
            }
        }
    }
    return self;}
    

    没有错误,但它不起作用。当我打开应用程序时,tableview仍然是空的,没有任何反应。怎么了?

0 个答案:

没有答案