2011-05-18 60 views
0

HII每一个检索到的数据和分组表视图中显示它

我是全新的,以OBJ C,我已经做了一个样本项目中,我有第一个屏幕2个显示屏上我有六个文本字段& 2个按钮命名为save和ViewData,点击保存数据后在文本框中输入d将被保存到sqliteData Base,&点击按钮ViewData它将导航到一个新的屏幕,该屏幕有一个分组表格,在这里我试图显示存储在sqlite中的数据,在分组表中查看我有6个部分我正在使用下面的代码来显示分组表中的数据视图,问题是分组表视图是只显示最后的数据这是进入文本字段,但我ED显示所有照耀处应根据该条显示

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

这里IM事先指定的文本行

- (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; 
} 

感谢的数据!

This是我的分组表视图snapshopt。我需要它通过文本字段中输入的数据建议立即进行删除下特定部分

+0

全新! :-) – 2011-05-18 06:44:35

+0

你想显示你的“临时”词典的键作为章节中的标题吗? – 2011-05-18 06:49:07

+0

什么我通过文本字段输入所有这些数据应显示在分组视图,,但我只得到最后输入的记录(如快照所示) – sujay 2011-05-18 07:00:56

回答

1

解决方案被视为只对最后的数据显示,

代替NSArray使用NSMutableArray

解决方案错误字段值,

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

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

这很好,我可以改变一个。这不是我的问题.iam只获取最后输入的值而不是所有记录 – sujay 2011-05-18 07:20:44

+0

你检查了numberOfRowsForSection的返回值吗? – KingofBliss 2011-05-18 07:24:13

+0

@sameer发布的代码 - (NSInteger的)numberOfRowsInSection:(NSInteger的)部方法 – KingofBliss 2011-05-18 07:27:14

相关问题