0

NSMutableArray の反復処理がどのように機能するのか疑問に思っていましたが、objectAtIndex を呼び出すと、「*** -[NSCFSet objectAtIndex:]: unrecognized selector sent to instance 0x...」で失敗します。

ここにいくつかのサンプル コードがあります。プログラムは大きすぎて全体を共有できないので、これで十分だと思います。コードは、XCode の最新の iPhone シミュレーターで実行されます。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 RDLogString(@"Creating cell @ row no. %d", indexPath.row);
 CPPlayerAppDelegate * appDelegate = [[UIApplication sharedApplication] delegate];
 RDLogString(@"Conversations: %p. Item count: %d", appDelegate.distribution.conversations, appDelegate.distribution.conversations.count);  
 //This works  
 for(CPConversation * x in appDelegate.distribution.conversations){
  RDLogString(@"Pointer: %p with name %@", x, x.name);
 }  
 //This fails with aforementioned error  
 CPConversation * conversationAtCurrentIndex = [appDelegate.distribution.conversations objectAtIndex: indexPath.row];

フォーマットが悪くて申し訳ありませんが、まだそれを理解しています。:)

前もってありがとう、ニック

4

2 に答える 2

1

objectAtIndex:は一部、NSArrayではありませんNSSet。これは、appDelegate.distribution.conversationsが返され、NSSetが必要であることを意味しますNSArray

于 2009-11-29T00:14:41.567 に答える
0

その例外メッセージは、受信クラスが認識または応答しないセレクターを含むメッセージを送信していることを示しています。この場合、タイプ(または単に)objectAtIndex:のオブジェクトにメッセージを送信しています。NSCFSetNSSet

これは、何が何であれappDelegate.distribution.conversations、それが NSArray であることを期待しているが、実際には NSSet であることを意味します。そこにアクセスするオブジェクトをどのように作成していますか?

于 2009-11-29T00:15:11.270 に答える