我有包含删除按钮,并添加按钮时触发
cell.coupon_add.tag = indexPath.row
cell.coupon_add?.layer.setValue(id, forKey: "coupon_id")
cell.coupon_add?.layer.setValue(uID, forKey: "user_id")
cell.coupon_add?.addTarget(self, action: #selector(ViewController.addItem(_:)), forControlEvents: UIControlEvents.TouchUpInside)
func addItem(sender:UIButton) {
let point : CGPoint = sender.convertPoint(CGPointZero, toView:collectionview)
let indexPath = collectionview!.indexPathForItemAtPoint(point)
let cell = collectionview.dequeueReusableCellWithReuseIdentifier("listcell", forIndexPath: indexPath!) as! ListCell
let coupon_id : String = (sender.layer.valueForKey("coupon_id")) as! String
let user_id : String = (sender.layer.valueForKey("user_id")) as! String
if user_id == "empty" {
self.login()
}else{
print("adding item**",indexPath)
cell.coupon_add.hidden = true
cell.coupon_del.hidden = true
let buttonRow = sender.tag
print(buttonRow)
}
}
我想,当触发隐藏的添加按钮的CollectionView。我刚刚得到的indexPath的价值,但我不知道如何来隐藏它不刷新的CollectionView
@ funi1234我尝试你的代码,它不工作 –
也许[这](http://stackoverflow.com/a/20297056/5779168)回答将帮助 – tahavath
@tahavath let indexArray = NSArray(object:indexPath!) self.collectionview.reloadItemsAtIndexPaths(indexArray as! [NSIndexPath])我尝试像这样我崩溃可以检查原因 –