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;
}
?あなたの 'NSArray * Names'はフィルタリングされていますか? –
あなたは両方を1つの文字列に追加しなければならず、次にテーブルビューラベルに設定することができます(そしてあなたの姓の配列はどこですか?) –