iPhone NSBundle的使用

本文摘自:http://liwpk.blog.163.com/blog/static/363261702011573638250/

 

NSBundle束,是一种特定的文件类型,其中的内容遵循特定的结构。

NSBundle的一个主要作用是 获取Resources文件夹中的资源

使用主束来获取需要的资源文件:

NSBundle *bundle = [NSBundle mainBundle];

NSString *plistPath = [bundle pathForResource:@"statedictionary" ofType:@"plist"];

或者简写成一行:

NSString *path = [[NSBundle mainBundlepathForResource:@"sortednames" ofType:@"plist"];

NSDictionary *dict = [[NSDictionary allocinitWithContentsOfFile:path];

 

 

例如:
    // get an image from the main app bundle
NSBundle *appBundle = [NSBundle mainBundle];
NSString *path = [appBundle pathForResource:@"myImage" ofType:@"png"];
UIImage *image = [[UIImage alloc]initWithContentsOfFile:path];
经过测试,创建工程自带的plist文件是无法获取其路径的。

 

posted on 2011-12-28 14:19  wtq  阅读(894)  评论(0编辑  收藏  举报