これがSwift3.1コードです
// make a cell for each cell index path
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
// get a reference to our storyboard cell
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath as IndexPath) as! BlueCircleViewCell
// Use the outlet in our custom class to get a reference to the UILabel in the cell
cell.bgImage.image = UIImage(named: items[indexPath.row])
cell.addButton.addTarget(self, action: #selector(addCircle(_:)), for: .touchUpInside)
// cell.backgroundColor = UIColor.cyan // make cell more visible in our example project
return cell
}
func addCircle(_ sender:UIButton){
//CGPoint buttonPosition = [sender convertPoint:CGPointZero toView:self.tableView];
let buttonPosition:CGPoint = sender.convert(.zero, to: self.collectionView)
let indexPath:IndexPath = self.collectionView.indexPathForItem(at: buttonPosition)!
onAddBlueCircle(indexPath: indexPath)
}