开发者

retrieved data from sqlite database and displaying it on grouped table view

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]in开发者_开发知识库itWithObjects: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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜