问题描述
苹果说:
"默认值为 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)")
}
}
如果自定义项出现在任何系统菜单项之后的菜单中,为什么会发生这种情况?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)