为什么我的自定义菜单项出现在某些系统菜单项之前?

问题描述

苹果说:

"认值为 nil(无自定义菜单项)。每个菜单项都是一个 UIMenuItem 类的实例。您可以创建自己的菜单项, 每个都有自己的标题和动作选择器,并将它们添加到 通过此属性编辑菜单自定义项目出现在菜单中 在任何系统菜单项之后。”

但这是马特的诺伊堡的例子:

@nonobjc fileprivate let capital = #selector(Cell.capital)
@nonobjc fileprivate let copy = #selector(UIResponderStandardEditactions.copy)

override func collectionView(_ collectionView: UICollectionView,shouldShowMenuForItemAt indexPath: IndexPath) -> Bool {
    
    let mi = UIMenuItem(title:"Capital",action:capital)
    UIMenuController.shared.menuItems = [mi]
    return true
}

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

override func collectionView(_ collectionView: UICollectionView,performAction action: Selector,withSender sender: Any?) {
    // in real life,would do something here
    let state = self.sections[indexPath.section].itemData[indexPath.row]
    if action == copy {
        print ("copying \(state)")
    }
    else if action == capital {
        print ("fetching the capital of \(state)")
    }
 
  }

enter image description here

}

如果自定义项出现在任何系统菜单项之后的菜单中,为什么会发生这种情况?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)