tags:

views:

17

answers:

1

i have a array containing dictionary ,i want to show the value in table view according to name field in dictionary suppose if name start with a,b ,c are in different section..,there are number of section according to the name field of dictionary ..here i am not able to do ho i get the number of row.. if any one know plz give then solution...

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    //---get the letter in each section; e.g., A, B, C, etc.---
    NSString *alphabet = [subscribeIndexArray objectAtIndex:section];

    //---get all states beginning with the letter---

    //NSMutableArray *states =[[NSMutableArray alloc]init];
    NSArray *states;
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];

    for(NSDictionary *dict in subscribeViewArray1)
    {
       states =[[dict valueForKey:@"name"] filteredArrayUsingPredicate:predicate];
    }

    //---return the number of states beginning with the letter---
    return [states count];
}
A: 

You need to have the state names in an array in order to filter them with a predicate.

Try this:

...
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet];
NSMutableArray *matchingStatesArray = [[NSMutableArray alloc] init];
for (NSDictionary *dict in subscribeViewArray1) {
       //get the state names in an array
    [matchingStatesArray addObject:[dict objectForKey:@"name"]];
    }
    [matchingStatesArray filterUsingPredicate:predicate];

    return [[matchingStatesArray autorelease] count];
}
MattLeff
I have done this but i want whole dictionary you are separting the array with name value
parvind