首页 > 代码库 > TableView中Model层数据
TableView中Model层数据
TableView中Model层数据
一、如果plist文件中的形式:NSArray —> NSDictionary —>NSArray
最外层的字典
+ (instancetype)carGroupsWithDict:(NSDictionary*)dict
{
return [[selfalloc]initWithDict:dict];
}
- (instancetype)initWithDict:(NSDictionary*)dict
{
self = [superinit];
[selfsetValue:dict[@"title"]forKey:@"title"];
self.carGroups= [SUNCarcarsWithArray:dict[@"cars"]];
return self;
}
+ (NSArray*)carGroups
{
NSArray *array = [NSArrayarrayWithContentsOfFile:[[NSBundlemainBundle]pathForResource:@"cars_total.plist"ofType:nil]];
NSMutableArray *arrayM = [NSMutableArrayarray];
for (NSDictionary*dict in array) {
[arrayM addObject:[selfcarGroupsWithDict:dict]];
}
return arrayM;
}
{
return [[selfalloc]initWithDict:dict];
}
- (instancetype)initWithDict:(NSDictionary*)dict
{
self = [superinit];
[selfsetValue:dict[@"title"]forKey:@"title"];
self.carGroups= [SUNCarcarsWithArray:dict[@"cars"]];
return self;
}
+ (NSArray*)carGroups
{
NSArray *array = [NSArrayarrayWithContentsOfFile:[[NSBundlemainBundle]pathForResource:@"cars_total.plist"ofType:nil]];
NSMutableArray *arrayM = [NSMutableArrayarray];
for (NSDictionary*dict in array) {
[arrayM addObject:[selfcarGroupsWithDict:dict]];
}
return arrayM;
}
最里层的数组
+ (instancetype)carWithDict:(NSDictionary*)dict
{
return [[selfalloc]initWithDict:dict];
}
- (instancetype)initWithDict:(NSDictionary*)dict
{
self = [superinit];
[selfsetValuesForKeysWithDictionary:dict];
return self;
}
+ (NSArray*)carsWithArray:(NSArray*)array
{
NSMutableArray *arrayM = [NSMutableArrayarray];
for (NSDictionary*dict in array) {
[arrayM addObject:[selfcarWithDict:dict]];
}
return arrayM;
}
{
return [[selfalloc]initWithDict:dict];
}
- (instancetype)initWithDict:(NSDictionary*)dict
{
self = [superinit];
[selfsetValuesForKeysWithDictionary:dict];
return self;
}
+ (NSArray*)carsWithArray:(NSArray*)array
{
NSMutableArray *arrayM = [NSMutableArrayarray];
for (NSDictionary*dict in array) {
[arrayM addObject:[selfcarWithDict:dict]];
}
return arrayM;
}
二、如果plist文件中的形式:NSArray —> NSDictionary
+ (instancetype)tgWithDict:(NSDictionary*)dict
{
return [[selfalloc]initWithDict:dict];
}
- (instancetype)initWithDict:(NSDictionary*)dict
{
self = [superinit];
if (self) {
[selfsetValuesForKeysWithDictionary:dict];
}
return self;
}
+ (NSMutableArray*)tgs
{
NSArray *array = [NSArrayarrayWithContentsOfFile:[[NSBundlemainBundle]pathForResource:@"tgs.plist"ofType:nil]];
NSMutableArray *arrayM = [NSMutableArrayarray];
for (NSDictionary*dict in array) {
[arrayM addObject:[selftgWithDict:dict]];
}
return arrayM;
}
{
return [[selfalloc]initWithDict:dict];
}
- (instancetype)initWithDict:(NSDictionary*)dict
{
self = [superinit];
if (self) {
[selfsetValuesForKeysWithDictionary:dict];
}
return self;
}
+ (NSMutableArray*)tgs
{
NSArray *array = [NSArrayarrayWithContentsOfFile:[[NSBundlemainBundle]pathForResource:@"tgs.plist"ofType:nil]];
NSMutableArray *arrayM = [NSMutableArrayarray];
for (NSDictionary*dict in array) {
[arrayM addObject:[selftgWithDict:dict]];
}
return arrayM;
}
TableView中Model层数据
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。