代码之家  ›  专栏  ›  技术社区  ›  Quailcreek

如何将上下文菜单限制为单个集合View

  •  0
  • Quailcreek  · 技术社区  · 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
            //    }
        }
    }
    
    1 回复  |  直到 1 年前
        1
  •  1
  •   matt    1 年前

    首先,在这两行注释掉的地方,检查您是否有正确的集合视图,如下所示:

    guard collectionView == list_CollectionView_Outlet else {
        return nil
    }