IPhone uses arrays to traverse images in a folder

Source: Internet
Author: User

1. Use arrays to traverse images in a folder,CodeAs follows:

 Nsfilemanager * filemanager = [nsfilemanager defaultmanager];

Nsarray * paths = nssearchpathfordirectoriesindomains (nsdocumentdirectory, nsuserdomainmask, yes); nsstring * documentsdirectory = [paths objectatindex: 0]; Nslog (@ "% d", [paths count]); Nserror * error = nil; Nsarray * filelist = [[nsarray alloc] init]; Nsmutablearray * filepath = [nsmutablearray arraywithcapacity: 100]; Nsmutablearray * imgarray = [nsmutablearray arraywithcapacity: 200]; // Nsarray * filepath = [[nsarray alloc] init]; Filelist = [filemanager contentsofdirectoryatpath: documentsdirectory error: & error]; For (nsstring * file in filelist ){ Nslog (@ "filename is: % @", file ); [Filepath addobject: [documentsdirectory stringbyappendingpathcomponent: file]; } For (INT I = 0; I <[filelist count]; I ++ ){ Uiimage * temp = [uiimage imagewithcontentsoffile: [filepath objectatindex: I]; [Imgarray addobject: temp]; } [Imgview1 setimage: [imgarray objectatindex: 0]; [Imgview2 setimage: [imgarray objectatindex: 1]; [Imgview3 setimage: [imgarray objectatindex: 2]; [Imgview4 setimage: [imgarray objectatindex: 3]; [Imgview5 setimage: [imgarray objectatindex: 4]; [Imgview6 setimage: [imgarray objectatindex: 5]; [Imgview7 setimage: [imgarray objectatindex: 6]; [Imgview8 setimage: [imgarray objectatindex: 7]; [Imgview9 setimage: [imgarray objectatindex: 8];

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.