// Called when a phone number is swiped for deletion. Illustrates how to delete a multivalue property protected void DeletePhoneNumber(int phoneNumberID) { using (ABAddressBook addressBook = new ABAddressBook()) { ABPerson contact = addressBook.GetPerson(contactID); // get the phones and copy them to a mutable set of multivalues (so we can edit) ABMutableMultiValue <string> phones = contact.GetPhones().ToMutableMultiValue(); // loop backwards and delete the phone number for (int i = phones.Count - 1; i >= 0; i--) { if (phones [i].Identifier == phoneNumberID) { phones.RemoveAt(i); } } // attach the phones back to the contact contact.SetPhones(phones); // save the changes addressBook.Save(); // show an alert, letting the user know the number deletion was successful new UIAlertView("Alert", "Phone Number Deleted", null, "OK", null).Show(); // repopulate the page PopulatePage(contact); } }
protected void BtnSaveChangesTouchUpInside(object sender, EventArgs e) { using (ABAddressBook addressBook = new ABAddressBook()) { ABPerson contact = addressBook.GetPerson(contactID); if (contact != null) { // save contact name information contact.FirstName = txtFirstName.Text; contact.LastName = txtLastName.Text; // get the phones and copy them to a mutable set of multivalues (so we can edit) ABMutableMultiValue <string> phones = contact.GetPhones().ToMutableMultiValue(); // remove all phones data // HACK: Cast nint to int for (int i = (int)phones.Count - 1; i >= 0; i--) { phones.RemoveAt(i); } // add the phone number to the phones from the table data source for (int i = 0; i < PhoneNumberTableSource.labels.Count; i++) { phones.Add(new NSString(PhoneNumberTableSource.numbers [i]), new NSString(PhoneNumberTableSource.labels [i])); } // attach the phones back to the contact contact.SetPhones(phones); // save the address book changes addressBook.Save(); // show an alert, letting the user know information saved successfully new UIAlertView("Alert", "Contact Information Saved!", null, "OK", null).Show(); // update the page PopulatePage(contact); // we have to call reload to refresh the table because the action didn't originate // from the table. tblPhoneNumbers.ReloadData(); } else { new UIAlertView("Alert", "Please select a contact using the top right button", null, "OK", null).Show(); } } }