0

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

sujay
  • 1,845
  • 9
  • 34
  • 55
  • Do you want to display the keys of your "temp" dictionary as title in section? – Alex Terente May 18 '11 at 06:49
  • what ever i enter through the text field all those data should be displayed in the grouped view,,but i am getting only last enterd record (as shown in the snapshot) – sujay May 18 '11 at 07:00

1 Answers1

1

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];
KingofBliss
  • 15,055
  • 6
  • 50
  • 72
  • that is fine , i can change tat one. that is not my problem.iam getting only the last entered value instead of all the records – sujay May 18 '11 at 07:20
  • did you check the return value of numberOfRowsForSection? – KingofBliss May 18 '11 at 07:24
  • @sameer post the code of - (NSInteger)numberOfRowsInSection:(NSInteger)section method – KingofBliss May 18 '11 at 07:27
  • @KingofBliss - (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section { NSArray *listData =[self.tableContents objectForKey:[self.sortedKeys objectAtIndex:section]]; return [listData count]; } – sujay May 18 '11 at 08:34
  • Instead of NSArray *listData use NSMutableArray *listData – KingofBliss May 18 '11 at 09:44
  • i tried its still not working,it ll be very help ful if u give any related code or tutorial – sujay May 18 '11 at 09:49