且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 sqlite 数据库中检索数据并将其显示在分组表视图上

更新时间:2022-12-12 09:52:45

只显示最后一个数据的解决方案,

使用 NSMutableArray 代替 NSArray.

字段值错误的解决方法,

您的问题可能出在插入本身,

Your problem may be in insertion itself,

 NSArray *arrTemp1 = [[NSArray alloc]initWithObjects:InsertRecord.strsixth,nil];
 NSArray *arrTemp2 = [[NSArray alloc]initWithObjects:InsertRecord.strfifth,nil];

您正在将价格值插入日期字段,我认为是这样.请检查一下.

You are inserting price value into date field, i think so. Please check that.

将您的代码更改为,

NSMutableArray *arrTemp1 = [[NSMutableArray alloc]init];
NSMutableArray *arrTemp2 = [[NSMutableArray alloc]init];
NSMutableArray *arrTemp3 = [[NSMutableArray alloc]init];
NSMutableArray *arrTemp4 = [[NSMutableArray alloc]init];
NSMutableArray *arrTemp5 = [[NSMutableArray alloc]init];
NSMutableArray *arrTemp6 = [[NSMutableArray alloc]init];

for(int intVar=0;intVar < [appDelegate.arrObjects count];intVar++)
    {
    insertUpdateDelete *InsertRecord = [appDelegate.arrObjects objectAtIndex:intVar];

    NSLog(@"InsertRecord:%@",InsertRecord);

    [arrTemp1 addObject:InsertRecord.strsixth];
    [arrTemp2 addObject:InsertRecord.strfifth];
    [arrTemp3 addObject:InsertRecord.strFourth];
    [arrTemp4 addObject:InsertRecord.strLogin];
    [arrTemp5 addObject:InsertRecord.strMiddleName];
    [arrTemp6 addObject:InsertRecord.strMiddleName];
    }
 NSDictionary *temp =[[NSDictionary alloc]initWithObjectsAndKeys:arrTemp1,@"Item Name",arrTemp2,@"Manufacturer",arrTemp3,@"Weight of Item",arrTemp4,@"Num of Item",arrTemp5,@"Price of Item",arrTemp6,@"MFG Date",nil];

    self.tableContents =temp;
    [temp release];
    NSLog(@"table %@",self.tableContents);
    NSLog(@"table with Keys %@",[self.tableContents allKeys]);
    self.sortedKeys =[[self.tableContents allKeys] sortedArrayUsingSelector:@selector(compare:)];
    NSLog(@"sorted %@",self.sortedKeys);

    [arrTemp1 release];
    [arrTemp2 release];
    [arrTemp3 release];
    [arrTemp4 release];
    [arrTemp5 release];
    [arrTemp6 release];