标签:ios开发
-(NSArray *)getdataFromDatabase { NSString *path = [self getDBPath]; NSLog(@"path ==== %@",path); NSLog(@"self.getDBPath == %@",[self getDBPath]); FMDatabase *membersDB = [FMDatabase databaseWithPath:path]; if (![membersDB open]) { NSLog(@"Failed to open membersDB"); return nil; [membersDB close]; } NSMutableArray *array = [NSMutableArray array]; FMResultSet *rs = [membersDB executeQuery:@"SELECT * FROM Member"];//这里数组为空 容易出错 <pre name="code" class="objc"> <span style="color:#FF0000;"> Member *member = [[Member alloc]init]; while ([rs next]) { member.name = [rs stringForColumn:@"Name"]; member.age = [rs intForColumn:@"Age"]; member.sex = [rs intForColumn:@"Sex"]; member.height = [rs intForColumn:@"Height"]; member.Weight = [rs intForColumn:@"Weight"]; member.icon = [UIImage imageWithData:[rs dataForColumn:@"Photo"]]; NSLog(@"member.name ============= %@",member.name); [array addObject:member];</span> } [membersDB close];<span style="color:#FF0000;"> NSLog(@"array[0] == %@,\narray[1] == %@,\narray[2]==%@",[array[0] name],[array[1] name],[array[2] name]);</span> return [array copy]; } </span>
-(NSArray *)getdataFromDatabase { NSString *path = [self getDBPath]; NSLog(@"path ==== %@",path); NSLog(@"self.getDBPath == %@",[self getDBPath]); FMDatabase *membersDB = [FMDatabase databaseWithPath:path]; if (![membersDB open]) { NSLog(@"Failed to open membersDB"); return nil; [membersDB close]; } NSMutableArray *array = [NSMutableArray array]; FMResultSet *rs = [membersDB executeQuery:@"SELECT * FROM Member"];//这里数组为空 容易出错 while ([rs next]) { <pre name="code" class="objc"> <span style="color:#FF0000;">Member *member = [[Member alloc]init];</span>
member.name = [rs stringForColumn:@"Name"]; member.age = [rs intForColumn:@"Age"]; member.sex = [rs intForColumn:@"Sex"]; member.height = [rs intForColumn:@"Height"]; member.Weight = [rs intForColumn:@"Weight"]; member.icon = [UIImage imageWithData:[rs dataForColumn:@"Photo"]]; NSLog(@"member.name ============= %@",member.name); [array addObject:member];</span> } [membersDB close];<span style="color:#FF0000;"> NSLog(@"array[0] == %@,\narray[1] == %@,\narray[2]==%@",[array[0] name],[array[1] name],[array[2] name]);</span> return [array copy]; }
项目中遇到的问题解决:深刻认识到类的初始化,布布扣,bubuko.com
标签:ios开发
原文地址:http://blog.csdn.net/feixiang_song/article/details/37528885