[ios] ContactsUI에서 연락처의 연락처를 이동하는 방법은 무엇인가요?
먼저, 드래그 앤 드롭 기능을 활용하여 ContactsUI에서 연락처를 이동할 수 있습니다. 이를 위해서 UITableViewDragDelegate
프로토콜을 구현하고 연락처 테이블 뷰를 설정해야 합니다.
아래는 연락처를 이동하는 간단한 예시 코드입니다.
extension YourViewController: UITableViewDragDelegate {
func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
let contact = contacts[indexPath.row]
let itemProvider = NSItemProvider(object: contact)
let dragItem = UIDragItem(itemProvider: itemProvider)
return [dragItem]
}
func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
let movedContact = contacts.remove(at: sourceIndexPath.row)
contacts.insert(movedContact, at: destinationIndexPath.row)
}
}
위 코드에서 YourViewController
는 현재 뷰 컨트롤러의 이름을 나타냅니다.
또 다른 방법으로는 CNContactPickerViewController
를 사용하여 연락처를 선택하고 이동할 수 있습니다. 이를 위해서는 CNContactPickerDelegate
프로토콜을 구현하고 해당 델리게이트 메서드에서 연락처를 이동하는 로직을 구현해야 합니다.
이러한 방법을 통해 ContactsUI를 사용하여 연락처를 이동할 수 있습니다.