swift

swift - 꾹 눌렀을때 메뉴 나타나게하기 UIContextMenuConfiguration

Coding_happyytw 2023. 8. 14. 19:32
    func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
        return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { (_: [UIMenuElement]) -> UIMenu? in
            
            let btn1 = UIAction(title: "좋아요", image: UIImage(systemName: "hand.thumbsup")) { (UIAction) in
                print("좋아요 클릭됨")
            }
            let btn2 = UIAction(title: "삭제하기", image: UIImage(systemName: "hand.thumbsup")) { (UIAction) in
                print("삭제하기 클릭됨")
            }
            return UIMenu(children: [btn1,btn2])
        }
    }

위처럼 코드를 사용하면 아래 사진처럼 꾹 눌렀을때 내가 추가한 메뉴를 띄우고 원하는 동작을 이후에 수행할 수 있다.