现将在iOS开发中调用本地plist文件并封装为NSDictionary字典类型做成图片。例子均是来自《ios5开发基础教程》中的章节,分别为《表视图--08 - Sections2》、《加速计---19 - ShakeAndBreak》 、《标签栏和选取器 07-MyPicker》 ,例子下载地址:点击打开链接
方法一:
NSString *path= [[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"]; NSDictionary *dict =[[NSDictionary alloc] initWithContentsOfFile:path];方法二:
NSURL *plistURL = [[NSBundle mainBundle] URLForResource:@"stateddictionary" withExtension:@"plist"]; NSDictionary *dict = [NSDictionary dictionaryWithContentsOfURL:plistURL];或者将方法一与方法二综合:
NSString *path= [[NSBundle mainBundle] pathForResource:@"sortednames" ofType:@"plist"]; NSURL *plistURL = [NSURL fileURLWithPath:path]; NSDictionary *dict = [NSDictionary dictionaryWithContentsOfURL:plistURL];