我在使用我的应用程序实现 RestKit/CoreData 时遇到了一些问题。使用 RKTwitterCoreData 示例应用程序并将其指向我的 web 服务以获取 json 提要,我得到了生成的 tableview:
目前遇到的问题:
- 即使我将primaryKeyAttribute 设置为orderID,刷新也会生成一个新的核心数据条目。
- 单元格 textLabel 显示与我的 Web 服务不匹配的奇怪 orderID
这是我的 applicationDidFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Initialize RestKit
RKObjectManager* objectManager = [RKObjectManager managerWithBaseURLString:@"http://mywebservice.com"];
// Enable automatic network activity indicator management
objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;
NSString *databaseName = @"RKTwitterData.sqlite";
objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:databaseName usingSeedDatabaseName:nil managedObjectModel:nil delegate:self];
RKManagedObjectMapping* statusMapping = [RKManagedObjectMapping mappingForClass:[Order class] inManagedObjectStore:objectManager.objectStore];
statusMapping.primaryKeyAttribute = @"orderID";
[statusMapping mapKeyPath:@"id" toAttribute:@"orderID"];
[statusMapping mapAttributes:@"created_at", nil];
// Register our mappings with the provider
[objectManager.mappingProvider setObjectMapping:orderMapping forResourcePathPattern:@"/orders"];
// Create Window and View Controllers
RKTwitterViewController* viewController = [[[RKTwitterViewController alloc] initWithNibName:nil bundle:nil] autorelease];
UINavigationController* controller = [[UINavigationController alloc] initWithRootViewController:viewController];
UIWindow* window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
[window addSubview:controller.view];
[window makeKeyAndVisible];
return YES;
}
/orders 处的 json 结果:
对处理这个问题有什么建议吗?谢谢!