2017-02-20 4 views
1

これは私をナットにしている、私は何時間も読んできたし、すべてを試して、このボタンセレクタを動作させる。これは難しいことではありません。セレクタ内のボタンのコレクションビューセル

CellForItemAt内でボタンタグを設定してボタンを呼び出してみます。 、および括弧の組み合わせの任意の他の数と、私はまだ認識されていないセレクタを取得する:私が試した

cell.deleteCellButton.tag = indexPath.item 
cell.deleteCellButton.addTarget(self, action: #selector(deleteCellButtonTapped(sender:)), for: UIControlEvents.touchUpInside) 

は、(_ :)、「deleteCellButtonTapped」。私はなぜオートコンプリートが(送信者:)を推薦するのか分からない私はこれまでに見たことがない。

はその後、私のボタン機能:

addTarget(self, action: #selector(deleteCellButtonTapped(sender:)), for: .touchUpInside) 
正常に動作します

func deleteCellButtonTapped(sender: UIButton!) { 
    self.packArray.remove(at: sender.tag) 
     print(packArray.count) 
    self.outerCollectionView.deleteItems(at: [IndexPath(item: sender.tag, section: 0)]) 

    self.outerCollectionView.reloadData() 
    self.outerCollectionView.layoutIfNeeded() 
} 
+0

#selector(自己の作品

class MyClassViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { .... // Other implementation methods func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { ....// create cell object and dequeue cell.deleteCellButton.addTarget(self, action: #selector(MyClassViewController.deleteCellButtonTapped(_:)), for: .touchUpInside) return cell } func deleteCellButtonTapped(_ sender: Any) { // your method implementation print("Selector method called") } } 

希望deleteCellButtonTapped(送信者が:))私のために働きました。 – Anuraj

答えて

0

あなたはスウィフト3を使用している、とfunc deleteCellButtonTapped(sender: UIButton!)が同じクラスであると仮定。

0

の選択方法を参照してください。

あなたができることは、それがクラス名で始まるアクセスセレクタメソッドプレフィックスです。

あなたのクラス名はMyClassViewControllerとします。そして、あなたのコードは次のようになります。これは細かい

関連する問題