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

发布于 2024-11-07 22:28:59 字数 2992 浏览 0 评论 0原文

大家好,

我是 obj c 的新手,我做了一个示例项目,其中第一个屏幕上有 2 个屏幕,我有 6 个文本字段和 6 个文本字段。 2 个名为 save 和 ViewData 的按钮,单击文本字段中输入的保存数据将保存在 sqliteData Base 中,&单击 ViewData 按钮时,它将导航到一个具有分组表视图的新屏幕,这里我尝试显示存储在 sqlite 中的数据,在分组表视图中我有 6 个部分,我正在使用以下代码在分组表视图中显示数据,问题是分组表视图仅显示在文本字段中输入的最后一个数据,但我需要显示输入的所有数据应显示在此处的该部分下,

appDelegate = (iICS_testAppDelegate *)[[UIApplication sharedApplication] delegate];

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

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




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

    NSMutableArray *arrTemp4 = [[NSMutableArray alloc]initWithObjects:InsertRecord.strLogin,nil];
    NSMutableArray *arrTemp5 = [[NSMutableArray alloc]initWithObjects:InsertRecord.strMiddleName,nil];
    NSMutableArray *arrTemp6 = [[NSMutableArray alloc]initWithObjects:InsertRecord.strFirstName,nil];


    NSMutableDictionary *temp =[[NSMutableDictionary 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];
    }

我正在分配文本行

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //insertUpdateDelete *InsertRecord = [appDelegate.arrObjects objectAtIndex:indexPath.row];
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";

    NSArray *listData =[self.tableContents objectForKey:[self.sortedKeys objectAtIndex:[indexPath section]]];


    UITableViewCell * cell = [tableView 
                              dequeueReusableCellWithIdentifier:SimpleTableIdentifier];


    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:SimpleTableIdentifier] autorelease];
    }

    NSUInteger row = [indexPath row];

    //cell.textLabel.text = [appDelegate.arrObjects objectAtIndex:row];
    cell.textLabel.text = [listData objectAtIndex:row];




    return cell;
}

提前致谢!

这是我的分组表视图快照。我需要通过文本字段输入的数据应在特定部分下查看

hii every one

i am brand new to obj c, i have did a sample project where i have 2 screens on the first screen i have six text fields & 2 buttons named save and ViewData ,on click of save data which is entere d in the text field will be get saved in the sqliteData Base ,& on click of the button ViewData it will navigate to a new screen which has a grouped table view, here i am trying to display the data which is stored in the sqlite ,in the grouped table view i have 6 sections i am using following code to display the data in grouped table view,problem is grouped table view is displaing only the last data which is entered ih the text field,,but i need to display all the data which enterd should be shown under that section

appDelegate = (iICS_testAppDelegate *)[[UIApplication sharedApplication] delegate];

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

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




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

    NSMutableArray *arrTemp4 = [[NSMutableArray alloc]initWithObjects:InsertRecord.strLogin,nil];
    NSMutableArray *arrTemp5 = [[NSMutableArray alloc]initWithObjects:InsertRecord.strMiddleName,nil];
    NSMutableArray *arrTemp6 = [[NSMutableArray alloc]initWithObjects:InsertRecord.strFirstName,nil];


    NSMutableDictionary *temp =[[NSMutableDictionary 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];
    }

here im assigning the text for the row

- (UITableViewCell *)tableView:(UITableView *)tableView 
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //insertUpdateDelete *InsertRecord = [appDelegate.arrObjects objectAtIndex:indexPath.row];
    static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";

    NSArray *listData =[self.tableContents objectForKey:[self.sortedKeys objectAtIndex:[indexPath section]]];


    UITableViewCell * cell = [tableView 
                              dequeueReusableCellWithIdentifier:SimpleTableIdentifier];


    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:SimpleTableIdentifier] autorelease];
    }

    NSUInteger row = [indexPath row];

    //cell.textLabel.text = [appDelegate.arrObjects objectAtIndex:row];
    cell.textLabel.text = [listData objectAtIndex:row];




    return cell;
}

thanks in advance!

This is my snapshopt of grouped table view. I need the data which is entered through the text field shoul be viewed under particular section

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

春花秋月 2024-11-14 22:28:59

仅显示最后数据的解决方案

使用 NSMutableArray 代替 NSArray

错误字段值的解决方案,

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

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

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

将您的代码更改为,

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];

Solution for only the last data is displaying,

Instead of NSArray use NSMutableArray.

Solution for wrong field values,

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.

Change your code as,

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文