计数图像在我的[[NSBundle mainBundle] bundlePath] [英] Count of images in my [[NSBundle mainBundle] bundlePath]

查看:142
本文介绍了计数图像在我的[[NSBundle mainBundle] bundlePath]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 [[NSBundle mainBundle] bundlePath] 中查找特定我的文件夹....

How can you find count of images in [[NSBundle mainBundle] bundlePath] at particular my folder....

Eg:/ Users / Nag / Library / Application Support / iPhone Simulator / 4.2 / Applications / 4409487C-1035-4329-B38A-B6F21E00FC63 / MakeUp_IPhone.app / MyFolder

Eg: /Users/Nag/Library/Application Support/iPhone Simulator/4.2/Applications/4409487C-1035-4329-B38A-B6F21E00FC63/MakeUp_IPhone.app/"MyFolder"

推荐答案

http://www.ericd.net/2009/06/iphone-getting-images-from-your-bundle.html

http://www.cocoabuilder。 com / archive / cocoa / 239638-number-of-images-in-main-bundle-folder-iphone.html

检查上述链接。

以下是您的代码:

Check the above links. They may provide a solution to your problem.
Here is the code for you:

    totalCount = 0;
    NSArray *d = [[NSBundle mainBundle] pathsForResourcesOfType:@"jpg" inDirectory:nil];
    for(NSString *s in d)
    {
       if([[s lastPathComponent] hasPrefix:@"image_"]){
       totalCount++;
       }
    }

要从一个文件夹获取图像, 图片数量

For getting images froma a paticular folder, see this: count no.of images

    NSEnumerator *iter = [[NSFileManager defaultManager] directoryEnumeratorAtPath:[[NSBundle mainBundle] bundlePath]];
    int count = 0; // number of images
    for (NSString *path in iter) { // iterate through all files in the bundle
         if ([[path pathExtension] isEqualToString:@"png"]) { // test if the extension is "png"
            count++; // increment the number of images
            UIImage *img = [UIImage imageWithContentsOfFile:path];
            // do other things with the image
        }
    }

请参阅:

// create the route of localDocumentsFolder
NSArray *filePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//first use the local documents folder
NSString *docsPath = [NSString stringWithFormat:@"%@/Documents", NSHomeDirectory()];
//then use its bundle, indicating its path
NSString *bundleRoot = [[NSBundle bundleWithPath:docsPath] bundlePath];
//then get its content
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRoot error:nil];
// this counts the total of jpg images contained in the local document folder of the app
NSArray *onlyJPGs = [dirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.JPG'"]];
// in console tell me how many jpg do I have
NSLog(@"numero de fotos en total: %i", [onlyJPGs count]);
// ---------------

这篇关于计数图像在我的[[NSBundle mainBundle] bundlePath]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆