회사라는 엔터티를 사용하여 핵심 데이터 배열을 정렬하려고합니다. 그러나, 내 애플 리케이션은 현재 내가 사용하는 코드로 데이터를 정렬하지 않습니다. 무슨 일이야?핵심 데이터 정렬 오류
여기2013-11-15 17:07:59.615 Minutes[70925:a0b] (
"<NSManagedObject: 0x89d4d40> (entity: Device; id: 0x89bdff0 <x-coredata://29EA13EB-909E-46E8-B8FD-C71A9B6436CE/Device/p2> ; data: {\n company = Reading;\n name = 1;\n version = \"Minutes of Harry Potter\";\n})",
"<NSManagedObject: 0x89d4ad0> (entity: Device; id: 0x8986ff0 <x-coredata://29EA13EB-909E-46E8-B8FD-C71A9B6436CE/Device/p1> ; data: {\n company = Service;\n name = 2;\n version = \"Minutes of Community\";\n})",
"<NSManagedObject: 0x89d4db0> (entity: Device; id: 0x8997950 <x-coredata://29EA13EB-909E-46E8-B8FD-C71A9B6436CE/Device/p3> ; data: {\n company = Service;\n name = 0;\n version = \"Minutes of Blank\";\n})"
)
배열을 정렬하는 데 사용하는 코드이다 : 여기서
는 오류가 미리- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// Fetch the devices from persistent data store
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Device"];
self.devices = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];
fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:
@"company" ascending:YES]];
[self.tableView reloadData];
}
감사!
편집 : 예상대로
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.devices.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
NSManagedObject *device = [self.devices objectAtIndex:indexPath.row];
[cell.textLabel setText:[NSString stringWithFormat:@"%@ %@", [device valueForKey:@"name"], [device valueForKey:@"version"]]];
[cell.detailTextLabel setText:[device valueForKey:@"company"]];
return cell;
}
배열이 "회사"속성과 관련하여 올바르게 정렬 된 것으로 보입니다. –
나중에 정렬 대신 가져 오기 요청에 정렬 설명자를 직접 설정할 수 있습니다. –