2016-03-16 73 views
3

我有一個顯示聯繫人的表格視圖。 當我點擊單元格時,我想直接進入可編輯視圖,而不是去CNContactViewController並按下「編輯按鈕」。 現在我有以下幾點:出現在聯繫人中的聯繫人編輯視圖UI

firstview

secondview

我想跳過第二步。那可能嗎?

我正在使用的代碼是從蘋果的一樣:

let contacts = try contactStore.unifiedContactWithIdentifier 
     (contactIdentifier!, keysToFetch: toFetch) 
    let controller = CNContactViewController(forContact: contacts) 
     controller.contactStore = contactStore 
     controller.delegate = self 
     controller.editing = true 

     navigationController? 
      .pushViewController(controller, animated: true) 
     print(controller.editButtonItem()) 

    } catch { 
     print(error) 
    } 

編輯:或多或少,來說明什麼林試圖做的,是一樣的WhatsApp在他們的應用程序!謝謝!

回答

2

你有沒有試過這種方法?

let toFetch = [CNContactViewController.descriptorForRequiredKeys()] 

let contacts = try contactStore.unifiedContactWithIdentifier 
     (contactIdentifier!, keysToFetch: toFetch) 

let contactsViewController = CNContactViewController(forNewContact: contacts) 
contactsViewController.delegate = self 
contactsViewController.title = "Edit contact" 
contactsViewController.contactStore = contactStore 

self.navigationController?.pushViewController(contactsViewController, animated: true) 
+0

嗨!謝謝你的回答!但是這個函數「CNContactViewController(forNewContact:contacts)」帶來了我想要的視圖,除了創建一個新的聯繫人,而不是編輯已經存在的視圖。 –

+0

如果您傳入newContact參數的現有聯繫人,則應編輯該特定聯繫人。這是我在測試 – Jani

+0

時經歷的行爲,但當用戶完成編輯並點擊「保存」時,不會重複該聯繫人? –

相關問題