2017-06-14 6 views
0

をサブクラスUICollectionViewControllerに設定してカスタムアクションを表示しようとしていますが、何らかの理由でカット、コピー、ペーストのアクションが期待通りに表示されます。UICollectionViewControllerサブクラスでカスタムアクションを表示していないUIMenuController

コードここでは、私は、Webから参照をたくさん続くが、それらのどれもが、それは仕事になりません:

class CollectionViewController: UICollectionViewController, UICollectionViewDelegateFlowLayout { 

    fileprivate var items = [MyClass]() 

    // MARK: - UICollectionViewDataSource 
    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
     return items.count 
    } 

    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
     let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellIdentifier", for: indexPath) 
     /* update cell properties */ 
     return cell 
    } 

    // MARK: - UICollectionViewDelegate 
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { 
     return CGSize(width: itemSize, height: itemSize) 
    } 

    override func collectionView(_ collectionView: UICollectionView, canPerformAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) -> Bool { 
     return true 
    } 

    override func collectionView(_ collectionView: UICollectionView, performAction action: Selector, forItemAt indexPath: IndexPath, withSender sender: Any?) { 
     /* Do Something */ 
    } 

    override func collectionView(_ collectionView: UICollectionView, shouldShowMenuForItemAt indexPath: IndexPath) -> Bool { 
     return true 
    } 

    public func menuAction(_ sender: UIMenuItem) { 
     /* Action method*/ 
    } 
} 

は、次のようにメニュー項目を追加しようとしました:両方の

 let menuItem = UIMenuItem(title: SFLocalization.localizedString("Common-remove"), action: #selector(CollectionViewController.menuAction(_:))) 
     let menuController = UIMenuController.shared 
//  menuController.menuItems?.append(menuItem) 
     menuController.menuItems = [menuItem] 

viewDidLoadcollectionView(_ collectionView:, shouldShowMenuForItemAt) -> Bool

+0

同様の問題が発生しました。あなたは決して解決策を見つける運がありましたか? –

答えて

0

Omerの - このリンクをチェックアウトする:これらの方法を動かし、基本的http://dev.glide.me/2013/05/custom-item-in-uimenucontroller-of.html

を:

  • (BOOL)canPerformAction:(SEL)アクションwithSender:(ID)、送信者{

  • (BOOL)canBecomeFirstResponder {

... CollectioにnViewセルのサブクラスが機能します。このセレクタをセルデリゲートに戻す必要があります。

これで、カスタムメニューが表示されました。

関連する問題