* @author fangbmian, 16-03-18 10:03:50
*
* 获取本地品牌数据
*/
NSString *dbFilePath = [[NSBundle mainBundle] pathForResource:@"name" ofType:@"db"]
if (!dbFilePath) return
carBrandList = [NSMutableArray new]
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
queue = [FMDatabaseQueue databaseQueueWithPath:dbFilePath]
[queue inDatabase:^(FMDatabase *db)
{
FMResultSet *rs = [db executeQuery:@"select distinct CAR_BRAND,CAR_BRAND_LOGO from CAR_VEHICLE"]
while([rs next])
{
CarBrandInfoBean * info = [CarBrandInfoBean new]
info.carBrand = [rs stringForColumn:@"CAR_BRAND"]
info.carBrandLogo = [rs stringForColumn:@"CAR_BRAND_LOGO"]
[carBrandList addObject:info]
}
}]
})
/**
* @author fangbmian, 16-03-17 13:03:01
*
* item被点击
*
* @param brandName 品牌名称
*/
-(void)didClickItem:(NSString*)brandName
{
if (!queue) return
NSMutableArray *carList = [NSMutableArray new]
[queue inDatabase:^(FMDatabase *db)
{
NSString *sql = [NSString stringWithFormat:@"select CAR_BRAND,CAR_SERIES,CAR_YEAR,CAR_TYPE,CAR_GAS,CAR_ID from CAR_VEHICLE where CAR_BRAND = \'%@\'", brandName]
FMResultSet *rs = [db executeQuery:sql]
while([rs next])
{
CarInfoBean *info = [CarInfoBean new]
info.carBrand = [rs stringForColumn:@"CAR_BRAND"]
info.carSeries = [rs stringForColumn:@"CAR_SERIES"]
info.carYear = [rs stringForColumn:@"CAR_YEAR"]
info.carType = [rs stringForColumn:@"CAR_TYPE"]
info.carGas = [rs stringForColumn:@"CAR_GAS"]
info.carTypeId = [rs stringForColumn:@"CAR_ID"]
[carList addObject:info]
}
}]
}
2.创建数据模块
3.创建对应的类
这时候创建不是右键创建,通过主菜单 Editor ->Create NSManagedObject Subclass
4.自动会为数据模块创建两个类文件
6.添加数据
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)