UIMenu
一旦用户按下正确的,我试图弹出一个UIBarButton
,但问题是 UIMenu 没有弹出,我不知道为什么,如果你们能帮我解决这个问题会很酷。
我还添加了注释代码以向您展示所有尝试。
我的问题是当我设置
UIBarButton
但不确定时。顺便提一句!我没有使用计算属性,因为当我使用这种方式时我无法编辑它们,所以我只使用了一个普通的存储变量。
我的代码:
// MARK: - UIBarButtonItem Creation and Configuration
func configureUIButtons() {
// let toolbarButtonItems = [
// customTitleBarButtonItem,
// flexibleSpaceBarButtonItem,
// deleteBarButtonItem
// ]
let toolbarButtonItems = [
markBarButtonItem, flexibleSpaceBarButtonItem, deleteBarButtonItem
]
toolBar.setItems(toolbarButtonItems, animated: true)
}
var deleteBarButtonItem: UIBarButtonItem = UIBarButtonItem(title: "Delete", style: .plain, target: self, action: #selector(NotificationsViewController.deleteButtonItemClicked(_:)))
// var deleteBarButtonItem: UIBarButtonItem {
// let deleteBarButtonItem: UIBarButtonItem = UIBarButtonItem(title: "Delete", style: .plain, target: self, action: #selector(NotificationsViewController.deleteButtonItemClicked(_:)));
//
// return deleteBarButtonItem
//
// }
var flexibleSpaceBarButtonItem: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
// var flexibleSpaceBarButtonItem: UIBarButtonItem {
// return UIBarButtonItem(barButtonSystemItem: .flexibleSpace,
// target: nil,
// action: nil)
// }
var markBarButtonItem: UIBarButtonItem = UIBarButtonItem(title: "Mark", style: .plain, target: self, action: #selector(NotificationsViewController.markButtonItemClicked(_:)))
// MARK: - Actions
@objc
func deleteButtonItemClicked(_ barButtonItem: UIBarButtonItem) {
print("Delete Button is clicked \(barButtonItem).")
}
@objc
func markButtonItemClicked(_ barButtonItem: UIBarButtonItem ) -> UIMenu {
print("Mark is pressed")
let markMenu = UIMenu(title: "", children: [
UIAction(title: "Flag", image: UIImage(systemName: "flag")) { action in
print("Flag is pressed")
},
UIAction(title: "Mark as Unread", image: UIImage(systemName: "envelope.badge")) { action in
print("Mark as Unread is pressed")
},
])
return markMenu
}
// func menuItems() -> UIMenu {
// let markMenu = UIMenu(title: "", children: [
// UIAction(title: "Flag", image: UIImage(systemName: "flag")) { action in
// print("Flag is pressed")
// },
// UIAction(title: "Mark as Unread", image: UIImage(systemName: "envelope.badge")) { action in
// print("Mark as Unread is pressed")
// },
// ])
//
// return markMenu
// }
//