如何在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)
}
但是我在菜单项上崩溃还有什么工作要做,任何帮助都会受到赞赏,提前谢谢。
答案 0 :(得分:0)
从特定索引路径的数组或字典中删除数据。
重新加载集合视图数据。
override func collectionView(collectionView: JSQMessagesCollectionView!, didDeleteMessageAtIndexPath indexPath: NSIndexPath!)
{
//Code for delete data from array or dictionary
[JSQMessagesCollectionView reloaddata];
}
答案 1 :(得分:0)
reloadData
有一个很好的解决方法,但问题是其他的......
有人说你改变了dataSource数组,并且在调用deleteItemsAtIndexPaths
之前没有在collectionView中完成更改。
答案 2 :(得分:0)
查看JSQMessagesViewController.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];
}
}
所以你不应该打电话
self.collectionView?.deleteItemsAtIndexPaths([indexPath])
这
override func collectionView(collectionView: JSQMessagesCollectionView!, didDeleteMessageAtIndexPath indexPath: NSIndexPath!)
您只应该使用此方法从数据源中删除消息。