2011-05-18 63 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

相關問題