Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
755 views
in Technique[技术] by (71.8m points)

ios - How to dismiss context menu (UIContextMenu) programmatically?

I have an iOS app. Some UIViewControllers have automatically updated content, it means that app can get update (simple JSON) any time (but no more often than about 1 time in half an hour). View controllers have UICollectionView with UIContextMenu for iOS >= 13.0.

Some times arises a situation when the user has called the context menu, but the content of cell and its menu are no longer relevant. UICollectionView already reloaded (with resorting cells), but context menu still shown. I know when the update happens in my app and I want to dismiss open menu in this moment. So my question is - how to dismiss context menu programmatically?

Thanks for any help!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Hello Please try this solution.

func tableView(_ tableView: UITableView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) {
        animator.preferredCommitStyle = .dismiss 
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...