IOS Photo Multi-Select

Source: Internet
Author: User

We know that the Uikit framework gives us uiimagepickercontroller this controller to read the album resources, but with this controller we can only pick one photo, but what if we want to select multiple photos?

assetslibrary.framework With this framework, we can read all the photo resources in the album. This framework provides a number of classes:

AlassetslibraryRefers to the entire album Library
AlassetsgroupRefers to a folder in an album
Alasset Refers to photos, videos in a folder


Use of the above three classes:
The album object is first created through the Alassetslibrary class, and then the album object loops through the folder objects in the album:Alassetsgroup . Through each Folder object, iterate through all the albums, video objects in this folder:Alasset. This object contains the album, video data, through such a few traversal, we can get to the album All the photos, video data.

code:

1Alassetslibrary *libray =[[Alassetslibrary alloc] init]; 2 3       4 5     /* 6 7 traverse all folders through the Photo Gallery enumeration Alassetsgroup8 9 Usingblock: How many group folders, how many times block, each time the corresponding folder group sent overTen  One      */   A  -[Libray enumerategroupswithtypes:alassetsgroupsavedphotos usingblock:^ (alassetsgroup *group, BOOL *stop) {   -  the            -  -         if(Group! =Nil) {   -  +    -  +             //Set Filter Objects A  at //alassetsfilter *filter = [Alassetsfilter Allvideos];  -  - //[group Setassetsfilter:filter];  -  -                -  in             //through the folder enumeration traverse all the photo Alasset objects, how many photos, how many times the block is called -  to[Group enumerateassetsusingblock:^ (Alasset *result, Nsuinteger index, BOOL *stop) {   +  -                 if(Result! =Nil) {   the  *                     //to store the result object in an array $ Panax Notoginseng [_data Addobject:result];  -  the                 }   +  A             }];  the  +         }   -  $            $  -         //refresh table, show photos -  the [_tableview Reloaddata];  - Wuyi            the  -} failureblock:^ (Nserror *error) {   Wu  -            About  $}];

The above code is retrieved by looping through all the album Object alasset, then stored in the array object _data , and then displayed in the cell by UITableView.

The following is the creation of the cell, and the data in the alasset object is obtained and displayed:

1-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {2 3         return_data.count; 4 5     }  6 7       8 9-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath {Ten  One            A  -         StaticNSString *identify =@"Imagecell";  -  the            -  -UITableViewCell *cell =[TableView dequeuereusablecellwithidentifier:identify];  -  +            -  +         if(Cell = =Nil) {   A  atCell =[[[ UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault reuseidentifier:identify] autorelease];  -  -         }   -  -            -  inAlasset *asset =[_data ObjectAtIndex:indexPath.row];  -  to            +  -         //gets the type of the media the  *NSString *type =[Asset Valueforproperty:alassetpropertytype];  $ Panax Notoginseng         //Media type is video -  the         if([type Isequaltostring:alassettypevideo]) { +  ACell.textLabel.text =@"Video";  the  +}Else {   -  $Cell.textLabel.text =@"Photos";  $  -         }   -  the            - Wuyi         //get thumbnail images of photos and videos the  -Cgimageref Cgimage =[asset thumbnail];  Wu  -UIImage *image =[UIImage Imagewithcgimage:cgimage];  About  $            -  -Cell.imageView.image =image;  -  A            +  the            -  $         returncell;  the  the}

So you can show all the pictures in the album.

IOS Photo Multi-Select

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.