我有包含刪除按鈕,並添加按鈕時觸發
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])我嘗試像這樣我崩潰可以檢查原因 –