加载plist文件中的数据,两种方法
来源:互联网 发布:淘宝新人礼包怎么领取 编辑:程序博客网 时间:2024/06/03 18:53
NSString *path = [[NSBundlemainBundle] pathForResource:@"data"ofType:@"plist"];
NSDictionary *drinkDictionary = [[NSDictionaryalloc] initWithContentsOfFile:path];
NSArray *array_ = [drinkDictionaryobjectForKey:@"drinks"];
NSDictionary *dic=[array_objectAtIndex:index];
NSString *name=[dicobjectForKey:@"name"];
NSArray *arrayStr= [[dic objectForKey:@"material"]componentsSeparatedByString:@"\r"];//将string划分为数组,以换行的形式显示出来
NSMutableString *string_ = [[NSMutableStringalloc] initWithString:@""];
for (int i =0; i < [array_ count]; i++) {
[string_appendFormat:@"<div style='background:rgba(100, 100, 255, 0) none repeat scroll 0 0 !important;filter:Alpha(opacity=0);width:300;height:24px;'><span style='position:relative;color:black'>%@</span></div>",[array_objectAtIndex:i]];
}
[string_appendString:@""];
materalWebView.frame =CGRectMake(20,490,280, [array_count] * 40);//UIWebView *materalWebView;
[materalWebViewloadHTMLString:string_ baseURL:nil];
#pragma mark -loaddrinkData
-(NSArray*)loadDinkInfoData
{
static NSArray *__drinkData =nil; // only load the imageData array once
if (__drinkData == nil) {
// read the filenames/sizes out of a plist in the app bundle
NSString *path = [[NSBundlemainBundle] pathForResource:@"DrinkInfoDataList"ofType:@"plist"];
NSData *plistData = [NSData dataWithContentsOfFile:path];
NSString *error; NSPropertyListFormat format;
__drinkData = [[NSPropertyListSerializationpropertyListFromData:plistData
mutabilityOption:NSPropertyListImmutable
format:&format
errorDescription:&error]
retain];
if (!__drinkData) {
NSLog(@"Failed to read drinkData info. Error: %@", error);
[error release];
}
else NSLog(@"-----drink data=%@",__drinkData);
}
return __drinkData;
}
- (NSUInteger)drinkDataCount {
static NSUInteger __count =NSNotFound; // only count the data once
if (__count == NSNotFound) {
__count = [[selfloadDinkInfoData] count];
}
return __count;
}
- (NSString *)drinkNameAtIndex:(NSUInteger)index {
NSString *name = nil;
if (index < [self drinkDataCount]) {
NSDictionary *data = [[self loadDinkInfoData] objectAtIndex:index];
name = [datavalueForKey:@"name"];
}
return name;
}
- (NSArray *)drinkComponentAtIndex:(NSUInteger)index {
NSArray *_component = nil;
if (index < [self drinkDataCount]) {
NSDictionary *data = [[self loadDinkInfoData] objectAtIndex:index];
_component = [datavalueForKey:@"component"];
}
return _component;
}
- (NSString *)drinkMessageAtIndex:(NSUInteger)index {
NSString *message = nil;
if (index < [self drinkDataCount]) {
NSDictionary *data = [[self loadDinkInfoData] objectAtIndex:index];
message = [datavalueForKey:@"message"];
}
return message;
}
//image
- (UIImage *)imageAtIndex:(NSUInteger)index {
// use "imageWithContentsOfFile:" instead of "imageNamed:" here to avoid caching our images
NSString *imageName = [self imageNameAtIndex:index];
NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"];
return [UIImageimageWithContentsOfFile:path];
}
- (NSString *)imageNameAtIndex:(NSUInteger)index {
NSString *imagename = nil;
if (index < [self drinkDataCount]) {
NSDictionary *data = [[self loadDinkInfoData] objectAtIndex:index];
imagename = [datavalueForKey:@"imagename"];
}
return imagename;
}
- 加载plist文件中的数据,两种方法
- ios开发(plist文件数据加载) 使用数据模型的方法加载plist文件中的数据
- 164,将.plist文件中的数据加载到程序中
- 读取plist文件中的数据
- 懒加载、plist文件数据加载、图片显示
- 加载plist数据
- 加载.plist中的汉字
- NSBundle 加载 .plist文件
- 加载JSON文件,Plist文件
- plist 文件 存放数据
- plist文件取数据
- plist文件追加数据
- 两种方法将CListCtrl控件中列表中的数据保存到文件中
- iOS oc加载plist数据
- 将字典中的数据保存到plist文件中
- 把plist文件中的数据赋给数组
- cocos2dx中的内存加载PLIST
- Easyui 弹出加载中的遮罩的两种方法
- IE和firefox在JS用法方面的区别
- PNG做WinMobile程序快捷方式
- 无线上网卡安装与卸载时导致本地网络闪断
- linux开机流程
- 查找 EXC_BAD_ACCESS 问题根源的方法
- 加载plist文件中的数据,两种方法
- WP7-wav 合并demo
- 删除表空间操作
- C++程序设计实验报告(一)
- Android应用开发之SQLite数据库
- C++程序设计实验报告(二)
- SCI、EI和ISTP收录号的查询方法
- linux apt-get 命令大全
- 第八周实验指导