English 中文(简体)
IOS 核心数据查询——分类
原标题:IOS Core data fetch-request - sorting

我正在利用一种背景线索来收集迄今为止分类的记录数量有限。

一切工作都很顺利。 我删除了在国歌中的记录(表3)。

//this is done in the background thread
NSFetchRequest *frequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyEntity" 
                                            inManagedObjectContext:self.managedObjectContext];
[frequest setEntity:entity];
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc]
                                    initWithKey:@"date"     
                                    ascending:NO];

NSArray *descriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
[frequest setSortDescriptors:descriptors];

[frequest setFetchOffset:fetchOffset];    
[frequest setFetchLimit:20];

[frequest setResultType:NSManagedObjectIDResultType];

 NSError *fetchError;
 NSMutableArray *mutableFetchResults = [[self.managedObjectContext executeFetchRequest:frequest 
                                                                               error:&fetchError] mutableCopy];

国家扫盲和扫盲局(NSManagedObjectContextDidSaveNoification)的背景资料已经登记,并担任以下选任者。

//this is done in the background thread
-(void) didSavePersistenceStore:(NSNotification *)notification
{
    [self.managedObjectContext mergeChangesFromContextDidSaveNotification:notification];
}

The problem: After deleting a record, subsequent fetch results are not sorted with date anymore.

What am I missing ?

问题回答

第一,确保你不使用管理办法 反对案文与错误的解读。 你们可以呼吁在适当的情况下这样做。

Second, the fetch descriptor you use for the fetch does not persist. So, unless you keep fetching with the same sorting criteria, you won t get it that way.

如果你想要这种行为,就使用独一无二的成果控制器。 它将保持对数据库的预期看法。

从果树文献中获取:

If you set the value to NSManagedObjectIDResultType, this will demote any sort orderings to “best efforts” hints if you do not include the property values in the request.

您需要撰写对持久性储存或固定储存的所有改动。 待填补。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签