2016-06-07 35 views
0

我希望動態顯示圖像,例如,如果用戶選擇10張圖像,則應顯示所有圖像,現在如果用戶想要選擇5張圖像,則(10 + 5)15應該顯示圖像。如何實現這一功能?在objective-c中顯示圖像dynamicalli -c

我正在使用UIImagePickerController來選擇圖像,所以一次只能選擇1張圖片。我給了一個添加照片按鈕。

UIImagePickerController *galleryObj=[[UIImagePickerController alloc]init]; 
    galleryObj.sourceType=UIImagePickerControllerSourceTypePhotoLibrary; 
    galleryObj.allowsEditing = YES; 
    galleryObj.delegate=self; 
    [self presentViewController:galleryObj animated:YES completion:nil]; 

當用戶點擊添加照片按鈕時,上面的代碼會被執行。

+0

當用戶選擇從庫中的圖像,你可以存儲圖像或圖片網址陣列。 – Mahesh

+0

如何將圖像動態添加到數組? – CodeGuru

+0

Ketan,你還困惑嗎?如果您有任何疑問,請告訴我。 – Mahesh

回答

0

// GalleryViewcontroller.h

#import <UIKit/UIKit.h> 

@interface GallaryViewController : UIViewController<UIImagePickerControllerDelegate> 
{ 
    NSMutableArray *selectedImagesArray; 
} 
@end 

GalleryViewcontroller.m

@implementation GallaryViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    //allocating array 
    selectedImagesArray=[[NSMutableArray alloc]init]; 
} 


-(IBAction)openGallery:(id)sender 
{ 
    UIImagePickerController *galleryObj=[[UIImagePickerController alloc]init]; 
    galleryObj.sourceType=UIImagePickerControllerSourceTypePhotoLibrary; 
    galleryObj.allowsEditing = YES; 
    galleryObj.delegate=self; 
    [self presentViewController:galleryObj animated:YES completion:nil]; 

} 

#pragma mark UIImagePickerController Delegate 
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 
    [picker dismissViewControllerAnimated:YES completion:^{ 


     //here we are adding the image in array 
     [selectedImagesArray addObject:[info objectForKey:UIImagePickerControllerOriginalImage]]; 
     NSLog(@"%@",selectedImagesArray); 

     //reload your colleciton view or tableview or any other view which your using to show selected images 

     //you can get images by index 
     //UIImage *img=[selectedImagesArray objectAtIndex:0]; 


    }]; 
} 
@end