我正在尝试将其他类的数据放入选择器视图....但我对它有点问题....我如何使它正确进入选择器视图....
Fooditem.h
@interface Fooditems : NSObject
@property (nonatomic,assign) int group_id;
@property (nonatomic, assign)int _id;
@property (nonatomic,retain) NSString *name;
@property (nonatomic,assign) int prot_energy;
@property (nonatomic,assign) int fat_energy;
@property (nonatomic,assign) int carb_energy;
@property (nonatomic,assign) int energy;
@property (nonatomic,assign) int weight;
@property (nonatomic,assign) NSString *wname;
@end
这是DatabaseAccess.m文件的getWeight函数
-(NSMutableArray *) getWeight:(int)_id
{
//NSLog(@"inside getweight with _id = %@",_id );
NSMutableArray *fooditemsArray = [[NSMutableArray alloc] init];
NSLog(@"after alloc init fooditemsarray");
FMDatabase *db = [FMDatabase databaseWithPath:[Utility getDatabasePath]];
NSLog(@"after get db path");
[db open];
NSLog(@"SELECT name, weight FROM weight where prod_id=%d",_id );
NSString *prod_id_string = [NSString stringWithFormat:@"%d", _id];
NSString *query = [ @"SELECT name, weight from weight where prod_id= \"" stringByAppendingString:prod_id_string];
NSString *completequery = [query stringByAppendingString:@"\""];
NSLog(@"completequery is:");
NSLog(@"%@",completequery);
do
{
//NSLog(@"inside while loop");
Fooditems *fooditem = [[Fooditems alloc] init];
NSLog(@"getProductDetail: after alloc for fooditem");
fooditem.wname = [results stringForColumn:@"name"];
fooditem.weight = [results intForColumn:@"weight"];
NSLog(@"wname = %@",[results stringForColumn:@"name"]);
NSLog([results stringForColumn:@"name"]);
[fooditemsArray addObject:fooditem];
}while([results next]);
[db close];
NSLog(@"fooditemsArray count after db close is %d", [fooditemsArray count]);
return fooditemsArray;
}
然后是我的pickerview.m文件
- (void)viewDidLoad
{
NSLog(@"prod_id in weightView is %d",prod_id);
[self populateFoodItems];
NSArray *quan=[[NSArray alloc] initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6", nil];
self.quantity=quan;
Fooditems *fooditemtype = [self.fooditemsArray objectAtIndex:[self.fooditemsArray count]];
NSMutableArray *unit = [[NSMutableArray alloc]initWithObjects:@"%@",fooditemtype.wname,nil];
self.weights = unit;
[super viewDidLoad];
}