2016-06-07 71 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