代码之家  ›  专栏  ›  技术社区  ›  Nick

nscfset objectatindex无法识别的选择器,迭代工作

  •  0
  • Nick  · 技术社区  · 16 年前

    我想知道迭代NSmutableArray是如何工作的,但是当我调用ObjectAtindex时,它会失败,并显示“***-[nscfset objectAtindex::无法识别的选择器发送到实例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];
    

    抱歉,格式不好,还没弄清楚。:)

    事先谢谢, 尼克

    2 回复  |  直到 12 年前
        1
  •  1
  •   Dave DeLong    16 年前

    objectAtIndex: 是其中的一部分 NSArray 不是 NSSet . 这意味着你 appDelegate.distribution.conversations 正在返回 NSSET 你需要一个 不可变数组 .

        2
  •  0
  •   Bryan Henry    16 年前

    该异常消息告诉您正在发送一条带有选择器的消息,而接收类无法识别或响应该选择器。在这种情况下,您将发送一个 objectAtIndex: 发送给类型为的对象的消息 NSCFSet (或者只是 NSSet )

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