2012-02-17 6 views
0

iphoneでテーブルビューに辞書の配列を表示する方法をこんにちは友人セル上だけfirstnameのは、私はこれを取得するために使用されるコードである私にthis link私が表示、姓と名を欲しい

を与えられたいくつかのいずれかを答えてみてください表示され、両方のグループへの順序で各米国の状態(ステート名)の第一の手紙彼らは一緒にアルファベット順:

personarray = [[NSMutableArray alloc]init]; 
    [personarray addObjectsFromArray:dislist.Peoplelistarray]; 
    //short the personarray value: 
    NSSortDescriptor *asortDescriptor; 
    asortDescriptor=[NSSortDescriptor sortDescriptorWithKey:@"FirstName" ascending:YES selector:@selector(caseInsensitiveCompare:)]; 
    //asortDescriptor=[[NSSortDescriptor alloc]initWithKey:@"TagName" ascending:YES]; 
    NSArray *sortDescriptors=[NSArray arrayWithObject:asortDescriptor]; 
    [self.personarray sortUsingDescriptors:sortDescriptors]; 

    //---create the index--- 
    Frstname = [[NSMutableArray alloc] init]; 
    //check 
    NSMutableArray *tempArray = [[NSMutableArray alloc] init]; 
    for (NSDictionary *row in personarray) { 
     [tempArray addObject:[row valueForKey:@"FirstName"]]; 

     for (int i=0; i<[tempArray count]; i++){ 
      char alphabet = [[tempArray objectAtIndex:i] characterAtIndex:0]; 
      NSString *uniChar = [NSString stringWithFormat:@"%C", alphabet]; 
      if (![Frstname containsObject:uniChar]){ 
       [Frstname addObject:uniChar]; 



      } 

私はNSPredicateを使用した後、私は(字幕など)@“FirstName"@“LastName"の両方でテーブルビューのセルを移入する方法を理解する問題が生じています配列をソートする

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [Mytableview dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 
    } 
    if (isSearchOn) { 
     NSString *cellValue = [searchResult objectAtIndex:indexPath.row]; 
     cell.textLabel.text = cellValue; 
    } 
    else { 

    //---get the letter in the current section--- 
    NSString* alphabet = [Frstname objectAtIndex:[indexPath section]]; 
    //---get all states beginning with the letter--- 
    NSPredicate *predicate = 
    [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet]; 
    NSArray *Names = [[personarray valueForKey:@"FirstName"] filteredArrayUsingPredicate:predicate]; 
    if ([Names count]>0) { 
     //---extract the relevant firstname from the Names object--- 
     NSString *cellValue = [Names objectAtIndex:indexPath.row]; 
     cell.textLabel.text = cellValue; 

    } 
+1

?あなたの 'NSArray * Names'はフィルタリングされていますか? –

+0

あなたは両方を1つの文字列に追加しなければならず、次にテーブルビューラベルに設定することができます(そしてあなたの姓の配列はどこですか?) –

答えて

0

どのようにあなたのコードの最後にこのような何か、について:あなたが最後の名前の配列です

NSArray *firstNames = [[personarray valueForKey:@"FirstName"] filteredArrayUsingPredicate:predicate]; 
NSArray *lastNames = [[personarray valueForKey:@"LastName"] filteredArrayUsingPredicate:predicate]; 
    if ([firstNames count]>0) { 
     //---extract the relevant firstname from the Names object--- 
     NSString *firstName = [firstNames objectAtIndex:indexPath.row]; 
NSString *lastName = [lastNames objectAtIndex:indexPath.row]; 
NSString *cellValue = [NSString stringWithFormat:@"%@ %@",firstName, lastName]; 
     cell.textLabel.text = cellValue; 
} 
関連する問題