2012-08-02 3 views
0

배열에 선택 항목을 저장하는 다중 선택기가 있습니다. 그것은 애플 리케이션 사용 내에서 유지됩니다. 그러나 앱이 종료되면 선택보기가 제거됩니다. 내가 원했던 것은 배열에 저장 한 후, NSUserDefaults에 저장하려고했기 때문에 내가 앱을 열 때 선택이 여전히 존재할 것입니다. NSUserDefaults을 사용하여 인덱스 전체를 저장하는 방법은 무엇입니까?배열 정수/인덱스를 NSUserDefaults에 저장

- (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]; 

     }); 

    }); 

답변

0

그런

yourArray = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"KeyName"] mutableCopy]; 

키 이름이 동일해야합니다 배열을로드 배열

[[NSUserDefaults standardUserDefaults] setObject:yourArray forKey:@"KeyName"]; 
[[NSUserDefaults standardUserDefaults] synchronize]; 

를 저장 : 여기

imagepicker 뷰 부품의 내 하중입니다

관련 문제