如何将上下文菜单限制为单个collectionView

问题描述 投票:0回答:1

我有一个包含三个集合视图的视图。我希望集合视图之一具有上下文菜单。如何控制只有其中一个有菜单?在下面的代码中,我注释掉了我试图用来限制哪个集合视图具有菜单的行。

如果我取消注释这些行并尝试将菜单限制为仅 list_CollectionView_Outlet,我会收到缺少返回的错误。 “实例方法中缺少预期返回‘UIContextMenuConfiguration?’

这让我抓狂,我做错了什么?

extension Case_VC2: UICollectionViewDelegate
{
    func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration?
    {
        //        if collectionView == list_CollectionView_Outlet
        //        {
        gID = theCurrentArray[indexPath.row].ID
        name = theCurrentArray[indexPath.row].Name
        
        let configuration = UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { [weak self] _ in
            
            let edit = UIAction(title: K.Titles.edit, image: UIImage(named: "Edit2")) { _ in
                gHideBackBtn = false
                gTheDisabledCell = ""
                self?.addEditTrick()
            }
            
            let remove = UIAction(title: K.Titles.remove, image: UIImage(systemName: K.Icons.trash)) { _ in
                self?.delete_XRef_Item()
            }
            
            return UIMenu(title: "", image: nil, children: [edit, remove])
        }
        
        return configuration
        //    }
    }
}
ios swift xcode uicollectionview
1个回答
0
投票

首先,检查您是否拥有正确的集合视图:

guard collectionView == list_CollectionView_Outlet else {
    return nil
}
© www.soinside.com 2019 - 2024. All rights reserved.