2012-01-12 10 views
1

私は友人に質問しています。 私はアドレスブックと同様のiosアプリケーションを実装しています。名前と電子メールでセルを表示することができました。以下のコードをコピーしています。とにかく私の質問はcontactValue.nameの私の名前がcontactValue.emailの&メールです。今、私はそれらをセクションに貼り付ける必要があります。どのように私はそれらをセクションすることができます。私は、Aで始まるすべての名前を1つのセクションにするなどを意味します。iosアドレス帳同様のアプリ

id alphabet = [arrayOfCharacters objectAtIndex:[indexPath section]]; 

//---get all names beginning with the letter--- 
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet]; 
// How can I filter the names here using the above predicate condition.I have my names in contactValue.name. According to the names the emails should also placed in the cells. 


Contact* contactValue= (Contact*)[contactArray objectAtIndex:indexPath.row]; 

cell.textLabel.text=contactValue.name; 
cell.detailTextLabel.text=contactValue.email; 

@sbooth:そうuは次のような意味ですか?しかし、次のようにすると、コード行のフィルタ処理でNsArrayからNsMutableArrayに代入されているIncomapatibleポインタ型が表示されます。どういう意味ですか?

id alphabet = [arrayOfCharacters objectAtIndex:[indexPath section]]; 

//---get all states beginning with the letter--- 
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF beginswith[c] %@", alphabet]; 
//here names n contactArray are NsMutableArrays. 

names = [contactArray filteredArrayUsingPredicate:predicate]; 

if ([names count]>0) { 

Contact* contactValue= (Contact*)[names objectAtIndex:indexPath.row]; 

    cell.textLabel.text=contactValue.name; 
    cell.detailTextLabel.text=contactValue.email; 
+0

私は、あなたが持っている問題を理解するのに役立つと思います。連絡先リストを表示するために何を使用していますか?上のコードはどのようなコンテキストで呼び出されていますか? – sbooth

答えて

0

すべての連絡先はcontactArrayに保存されていますか?もしそうなら、[contactArray filteredArrayUsingPredicate:predicate]を試しましたか?

+0

idアルファベット= [arrayOfCharacters objectAtIndex:[indexPath section]]; // ---文字で始まるすべての状態を取得します。 NSPredicate * predicate = [NSPredicate predicateWithFormat:@ "SELF beginningwith [c]%@"、alphabet]; names = [contactArray filteredArrayUsingPredicate:predicate]; if([names count]> 0){ お問い合わせ* contactValue =(Contact *)[names objectAtIndex:indexPath.row]; cell.textLabel.text = contactValue.name; cell.detailTextLabel.text = contactValue.email; – jessy

+0

THANK U SO MUCH。 私はこの問題を解決することができます。私は次のようにしました: NSPredicate * predicate = [NSPredicate predicateWithFormat:@ "SELF.name beginswith [c]%@"、アルファベット]; NSMUtableArray * someArray =(NSMutableArray *)[contactArray filteredArrayUsingPredicate:predicate]; //基本的にキャストします。 私の答えが私のような人に役立つことを願っています。 – jessy

0

問題を解決できました。 @スーツ、それは働いたが、唯一のことはちょうどそれをキャストする必要があります。

(NSMutableArray*)array = (NSMutableArray*)[contactArray filteredArrayUsingPredicate:predicate]; 
関連する問題