这里我试图删除特定的索引数据,当从使用模型类保存的数组中按下删除按钮时,任何人都可以帮助我从数组中删除数据而不显示在集合视图中吗?
我在这里试过这段代码
我在这里声明为数组
var cartItemsModel = [CartItems]()
以下是我的删除按钮操作
@objc func deleteAction(sender : UIButton){
let buttonPosition = sender.convert(CGPoint(), to: cartCollectionView)
let indexPath = cartCollectionView.indexPathForItem(at: buttonPosition)
self.deleteIndexPath = indexPath
self.Index = sender.tag
let obj = cartItemsModel[(indexPath?.row)!]
self.cartItemsModel.remove(at: (indexPath?.row)!)
self.itemId = obj.itemID
self.price = obj.price
// view.isUserInteractionEnabled = false
let attribute = RappleActivityIndicatorView.attribute(style: .apple, tintColor: .white, screenBG: .darkGray, progressBG: .black, progressBarBG: .orange, progreeBarFill: .red, thickness: 4)
RappleActivityIndicatorView.startAnimatingWithLabel("Processing...", attributes: attribute)
// UIApplication.shared.beginIgnoringInteractionEvents()
if loginCheck == 1 {
let customerDeleteAPI = "\(domainName)/V1/carts/mine/items/\(itemId!)/"
customerItemsDeleteDownloadJsonWithURL(customerItemsAPI: customerDeleteAPI)
}else {
let deleteApi = "\(domainName)/en/V1/guest-carts/\(self.guestQuoteId!)/items/\(itemId!)/"
deleteItemsDownloadJsonWithURL(deleteItemsAPI: deleteApi)
}
}
下面根据响应调用delete api之后我试图删除所选的数组并且代码是
self.cartItemsModel.remove(at: (self.deleteIndexPath?.row)!)
我尝试了另一个代码,如下所示
self.cartItemsModel.remove(at: self.Index!)
答案 0 :(得分:0)
请检查以下标记的答案。它会解决你的问题。
delete item from collection view
但是,在您成功的API调用使用这些方法之后。
此外,请先在code D