コード例 #1
0
        protected void BtnAddPhoneNumberTouchUpInside(object sender, EventArgs e)
        {
            // get a reference to the contact
            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();

                // add the phone number to the phones via the multivalue.Add method
                phones.Add(new NSString(txtPhoneLabel.Text), new NSString(txtPhoneNumber.Text));

                // attach the phones back to the contact
                contact.SetPhones(phones);

                // save the address book changes
                addressBook.Save();

                // show an alert, letting the user know the number addition was successful
                new UIAlertView("Alert", "Phone Number Added", 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();
            }
        }
コード例 #2
0
        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();
                }
            }
        }