Ios 使用JSQMessageViewController删除消息崩溃

Ios 使用JSQMessageViewController删除消息崩溃,ios,swift,jsqmessagesviewcontroller,Ios,Swift,Jsqmessagesviewcontroller,如何在JSQMessageController中处理删除操作,我已经实现了这个方法 override func collectionView(collectionView: JSQMessagesCollectionView!, didDeleteMessageAtIndexPath indexPath: NSIndexPath!) { self.collectionView?.deleteItemsAtIndexPaths([indexPath]) } 也重写方法 overri

如何在JSQMessageController中处理删除操作,我已经实现了这个方法

override func collectionView(collectionView: JSQMessagesCollectionView!, didDeleteMessageAtIndexPath indexPath: NSIndexPath!) {

     self.collectionView?.deleteItemsAtIndexPaths([indexPath])

}
也重写方法

override func collectionView(collectionView: UICollectionView, shouldShowMenuForItemAtIndexPath indexPath: NSIndexPath) -> Bool {
   // Do the custom JSQM stuff
    super.collectionView(collectionView, shouldShowMenuForItemAtIndexPath: indexPath)
  // And return true for all message types (we don't want the long press menu disabled for any message types)
  return true
}

override func collectionView(collectionView: UICollectionView, canPerformAction action: Selector, forItemAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject?) -> Bool {
   super.collectionView(collectionView, canPerformAction: action, forItemAtIndexPath: indexPath, withSender: sender)
   return true
}

override func collectionView(collectionView: UICollectionView, performAction action: Selector, forItemAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject?) {
  super.collectionView(collectionView, performAction: action, forItemAtIndexPath: indexPath, withSender: sender)
}
但我在菜单项上遇到了问题,还有什么可以做的,任何帮助都将不胜感激,提前谢谢

  • 从特定索引路径处的数组或字典中删除数据

  • 重新加载集合视图数据

  • 从特定索引路径处的数组或字典中删除数据

  • 重新加载集合视图数据


  • 重新加载数据有一个很好的解决方法,但问题是其他的


    这意味着在调用
    deleteeitemsatindexpaths
    之前,您已经更改了数据源数组,并且没有在collectionView中进行更改。

    重新加载数据有很好的解决方法,但问题是其他的


    这意味着在调用
    DeleteItemsAndExpaths
    之前,您更改了dataSource数组,并且没有在collectionView中完成更改。

    查看JSQMessageViewController.m中的源代码:

    - (void)collectionView:(JSQMessagesCollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
    {
        if (action == @selector(copy:)) {
            id<JSQMessageData> messageData = [collectionView.dataSource collectionView:collectionView messageDataForItemAtIndexPath:indexPath];
            [[UIPasteboard generalPasteboard] setString:[messageData text]];
        }
        else if (action == @selector(delete:)) {
            [collectionView.dataSource collectionView:collectionView didDeleteMessageAtIndexPath:indexPath];
    
            [collectionView deleteItemsAtIndexPaths:@[indexPath]];
            [collectionView.collectionViewLayout invalidateLayout];
        }
    }
    

    您只应使用此方法从数据源中删除消息。

    查看JSQMessageViewController.m中的源代码:

    - (void)collectionView:(JSQMessagesCollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
    {
        if (action == @selector(copy:)) {
            id<JSQMessageData> messageData = [collectionView.dataSource collectionView:collectionView messageDataForItemAtIndexPath:indexPath];
            [[UIPasteboard generalPasteboard] setString:[messageData text]];
        }
        else if (action == @selector(delete:)) {
            [collectionView.dataSource collectionView:collectionView didDeleteMessageAtIndexPath:indexPath];
    
            [collectionView deleteItemsAtIndexPaths:@[indexPath]];
            [collectionView.collectionViewLayout invalidateLayout];
        }
    }
    

    您只应使用此方法从数据源中删除消息。

    由于未捕获的异常“NSInternalInconsistencyException”,崩溃会说什么/终止应用程序,原因是:“无效更新:第0节中的项目数无效。”。更新(8)后现有节中包含的项目数必须等于更新(8)前该节中包含的项目数,加上或减去从该节插入或删除的项目数(0插入,1删除),加上或减去移入或移出该节的项目数(0移入,0移出).“您好,亲爱的,这不是在集合中重新加载数据的正确解决方案。其原因是当我们快速滚动或索引路径不存在时出现问题请尝试下面的解决方案崩溃说明什么/由于未捕获异常“NSInternalInconsistencyException”终止应用程序,原因:“无效更新:节0中的项目数无效。项目数继续”更新(8)后现有节中的ned必须等于更新(8)前该节中包含的项目数,加上或减去从该节插入或删除的项目数(0插入,1删除),加上或减去移入或移出该节的项目数(0移入,0移出).'您好,亲爱的,这不是在集合中重新加载数据的正确解决方案。当我们快速滚动或索引路径不存在时,它会导致问题。请尝试下面的解决方案
    override func collectionView(collectionView: JSQMessagesCollectionView!, didDeleteMessageAtIndexPath indexPath: NSIndexPath!)