0
我有一个多选择器,我把它存储在一个数组中。它保留在应用程序使用中。但是,当应用程序退出时,它将删除选择视图。我想要的是将它保存到一个数组后,我将它保存在NSUserDefaults
,所以当我打开应用程序的选择仍然会在那里。我如何使用NSUserDefaults
作为整体存储索引,然后再次为拾取器加载索引。保存整数/索引到NSUserDefaults
这里是我的imagepicker
视图部分的负载:
- (void)loadAssets
{
count = 0;
[self.assets removeAllObjects];
AGIPCAssetsController *blockSelf = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
selectedPhotos = [[NSMutableArray alloc] initWithArray:blockSelf.imagePickerController.selection];
@autoreleasepool {
[blockSelf.assetsGroup enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
//ALAssetRepresentation* representation = [result defaultRepresentation];
// NSUInteger assetindex= [blockSelf.assetsGroup numberOfAssets];
if (result == nil)
{
return;
}
AGIPCGridItem *gridItem = [[AGIPCGridItem alloc] initWithAsset:result andDelegate:blockSelf];
if(count < blockSelf.imagePickerController.selection.count)
{
if (blockSelf.imagePickerController.selection != nil &&
[result isEqual:[selectedPhotos objectAtIndex:count]])
{
gridItem.selected = YES;
count++;
}
}
[blockSelf.assets addObject:gridItem];
}];
}
dispatch_async(dispatch_get_main_queue(), ^{
[blockSelf reloadData];
});
});