2009-06-14 12 views
0

私はここにコード上記のコード配列flashcardsNamesListでiphoneのnsdictionaryから値を取得する方法は?

-(void)getAllFlashCardsNames 
{ 
if ([listofitems count]==0) 
    listofitems = [[NSMutableArray alloc] init]; 
else 
    [listofitems removeAllObjects]; 

for(int i=0;i<listOfCategoryId.count;i++) 
{ 
    int j=[[listOfCategoryId objectAtIndex:i]intValue]; 
    [self getFlashCard:j];  
    NSArray *flashCardsNames = flashCardsNamesList; 
    NSArray *flashCardsids = flashCardsId; 
    NSLog(@"FLash Card Ids %@",flashCardsids);  
    NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:flashCardsNames,@"flashCards",flashCardsids,@"flashCardId",nil]; 
    [listofitems addObject:dictionary]; 

} 

}

がある関数を呼び出すときに、flashCardsIdは毎回変わる配列 で辞書を埋めるための関数を使用しています[自己getFlashCard:J ]; jはlistOfCategoryId配列から来るcategoryidを変更するパラメータです。

辞書から値を取得する方法uitableviewの異なるセクションに異なるflashcardsNamesを表示したいのですが。ここ

は値

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 
return [listofitems count]; 

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection: (NSInteger)section { 
    NSDictionary *dictionary =[listofitems objectAtIndex:section]; 
    NSLog(@"dictionary=%@",dictionary); 
    NSArray *array =[dictionary objectForKey:@"flashCards"]; 
    NSLog(@"array=%@",array); 
    NSLog(@"Section Count = %d",array.count); 
    return array.count; 
} 



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath { 
    static NSString *CellIdentifier = @"Cell"; 
    CustomCell *cell = (CustomCell *)[tableViewdequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) {  
     cell = [[[CustomCell alloc] initWithFrame:CGRectZero  reuseIdentifier:CellIdentifier] autorelease];  
    } 

    NSDictionary *dictionary =[listofitems objectAtIndex:indexPath.section]; 
    NSArray *array =[dictionary objectForKey:@"flashCards"]; 
    NSArray *array1=[dictionary objectForKey:@"flashCardId"]; 
    NSString *cellValue=[array objectAtIndex:indexPath.row]; 
    NSString *cellValue1=[array1 objectAtIndex:indexPath.row]; 
    [cell.FlashCardsNames setText:cellValue]; 
    [cell setFlashCardId:[cellValue1 intValue]]; 
    return cell; 
} 

を取得するために使用してコードイムですが、この方法 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

答えて

3

が、呼び出されていません-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath方法呼び出されません。

メソッドが実装されているオブジェクトをテーブルビューのデータソースとして設定しましたか? とUITableViewDelegateプロトコルに準拠しなければならない別のオブジェクトに作業の一部を渡します。テーブルビューのdataSourcedelegateとしてオブジェクトをIBまたはプログラムで設定する必要があります(データソースとデリゲートは異なるオブジェクトである可能性がありますが、通常は同じオブジェクトです)。詳細についてはthis articleをご覧ください。これが完了すると、オブジェクトはtableView:cellForRowAtIndexPath:tableView:numberOfRowsInSection:メソッドを処理しなければなりません。これらのメソッドは、テーブルビューでオブジェクトに対して呼び出されます。

また、行:

if ([listofitems count]==0) 
    listofitems = [[NSMutableArray alloc] init]; 

は意味がありません。配列が割り当てられているかどうかを確認しているかどうかを確認していないかどうかを確認していると仮定します。アレイが割り当てられていない場合は、nilとなるので、countを送信しても効果はありません。前に割り当てられていたが割り当てが解除されていてもでない場合は、nilに戻されたは悪いポインタになり、アプリケーションがクラッシュする可能性があります。それを割り当てる

良い方法は、あなたのUIApplicationDelegateサブクラスでこれを実装している場合は、あなたのクラスのawakeFromNibメソッド、またはapplicationDidFinishLaunching:方法でそうするだろう。 deallocメソッドでそれをリリースすることを忘れないでください。

+0

メソッドが実装されているオブジェクトをテーブルビューのデータソースとして設定しましたか? これはどういう意味ですか? numberOfRowsInSection:メソッドが呼び出されますが、このラインの戻り配列の0オブジェクト にNSArray *配列= [辞書objectForKey:@「フラッシュカード」] –

+0

私の編集 –

+0

方法のtableViewを見てみましょう。 私はここにこだわっています.. –

関連する問題