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:消息发送到类型NSCFSet(或只是NSSet)的对象。

这意味着无论appDelegate.distribution.conversations是什么,您都希望它是一个 NSArray,但它实际上是一个 NSSet。您如何创建在那里访问的对象?

于 2009-11-29T00:15:11.270 回答