2011-06-28 11 views
0

私は、次のオブジェクトを持つNSMutableArrayの持っている:私は事前に定義されたIDを持つセルの迅速な検索を必要とするいくつかの方法でNSMutableArrayのクイック検索????/

@interface MyViewCell : UITableViewCell { 

    NSUInteger id; 
    ..... 
    } 

を。どのようにそれを行うには最高の?

答えて

9

おそらく最も簡単な方法は- (NSUInteger)indexOfObjectPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicateを使用することです。ドキュメントhereを参照してください。

int index = [myArray indexOfObjectPassingTest: ^(id obj, NSUInteger idx, BOOL *stop) { 
    MyViewCell *cell = (MyViewCell *)obj; 
    BOOL result = (cell.id == someValue); 
    stop = &result; 
    return result; 
}]; 
+0

感謝。見つかったMyViewCellはどのように入手できますか?私が理解しているように、あらかじめ定義されたIDだけを検索しています。 –

+0

'[myArray objectAtIndex:index]' – highlycaffeinated

1

私はコードを試したときに、小さな問題が発生しました。コードを次の調整(を停止* )私のためにうまく働いた:

int index = [myArray indexOfObjectPassingTest: ^(id obj, NSUInteger idx, BOOL *stop) { 
    MyViewCell *cell = (MyViewCell *)obj; 
    BOOL result = (cell.id == someValue); 
    *stop = result; 
    return result; 
}]; 
+0

はい、それは小さな間違いです:) –

関連する問題