2014-10-31 28 views
0

要加入陣列添加的攝像頭拍攝的圖像,並加載在收集觀點,陣列顯示所有圖像如何添加攝像頭採集的圖像在陣列中的IOS

///here i get the capture image in picker 

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) 
{ 
     UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; 
     imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
     imagePicker.delegate = self; 
     imagePicker.allowsEditing = YES; 
     [self presentViewController:imagePicker animated:YES completion:nil]; 
} 


- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 

    // in this part how can add the camera capture image in array 
    // and load that array value in collection view.. 
} 

幫助我如何實現這一目標。 ..

回答

5

我沒有測試過什麼,我要寫,但你可以試試這個:

-(void)viewDidLoad { 

    //declare before NSMutableArray *_mutableArray; 
    _mutableArray = [[NSMutableArray alloc] init]; 
} 

... 

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { 
    //dismiss UIImagePickerController 
    [picker dismissViewControllerAnimated:YES completion:Nil]; 

    //take image from info 
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; 

    //store image into NSMutableArray 
    [_mutableArray addObject:image]; 

    //reload collectionView 
    [self.collectionView reloadData]; 
} 

collectionView cellForItemAtIndexPath

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    //this is a custom CollectionViewCell 
    CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath]; 

    cell.imageA.image = [_mutableArray objectAtIndex:indexPath.row]; 

    return cell; 

} 
+1

正確的代碼...我在cell.imageA.image = [_mutableArray objectAtIndex:indexPath.row]中犯了錯誤;部分非常感謝你... – srini 2014-10-31 10:06:11

+0

@srini imageA是我在自定義單元格中的自定義圖像..無論如何高興得到了幫助! :) – Ilario 2014-10-31 10:08:37

相關問題