From 46ad60aeb90d55087598687cfabd4e70232f55b0 Mon Sep 17 00:00:00 2001 From: bopang Date: Mon, 17 Jun 2013 18:25:29 -0400 Subject: [PATCH] Fix bug #11612 in Shared resource. Implement BtnSaveChangesTouchUpInside method to enable save contact function. Change some code in table data source to support phone number editing and saving. --- .../iPhone/Contacts/AddressBookScreen.xib.cs | 102 +++++++++++++++--- 1 file changed, 90 insertions(+), 12 deletions(-) diff --git a/SharedResources/SharedResources/Screens/iPhone/Contacts/AddressBookScreen.xib.cs b/SharedResources/SharedResources/Screens/iPhone/Contacts/AddressBookScreen.xib.cs index 5a80ed8d..30dd0292 100644 --- a/SharedResources/SharedResources/Screens/iPhone/Contacts/AddressBookScreen.xib.cs +++ b/SharedResources/SharedResources/Screens/iPhone/Contacts/AddressBookScreen.xib.cs @@ -151,7 +151,7 @@ namespace Example_SharedResources.Screens.iPhone.Contacts ABMutableMultiValue 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)); + phones.Add (new NSString (txtPhoneNumber.Text), new NSString (txtPhoneLabel.Text)); // attach the phones back to the contact contact.SetPhones (phones); @@ -202,7 +202,44 @@ namespace Example_SharedResources.Screens.iPhone.Contacts protected void BtnSaveChangesTouchUpInside (object sender, EventArgs e) { - + using(ABAddressBook addressBook = new ABAddressBook ()) + { + ABPerson contact = addressBook.GetPerson (contactID); + + // 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 phones = contact.GetPhones ().ToMutableMultiValue (); + + // remove all phones data + for (int i = 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 DeleteClicked; protected ABMultiValue phoneNumbers { get; set; } + public static List labels; + public static List numbers; + public PhoneNumberTableSource(ABMultiValue phoneNumbers) - { this.phoneNumbers = phoneNumbers; } + { + this.phoneNumbers = phoneNumbers; + if(labels == null) + labels = new List(); + else + labels.Clear(); + if(numbers == null) + numbers = new List(); + else + numbers.Clear(); + for (int i=0; i!$_", ""); - cell.PhoneNumber = phoneNumbers[indexPath.Row].Value.ToString (); + cell.dataIndex = indexPath.Row; + cell.txtLabel.EditingDidEnd += (sender, e) => { + labels[cell.dataIndex] = cell.PhoneLabel; + + }; + cell.txtPhoneNumber.EditingDidEnd += (sender, e) => { + numbers[cell.dataIndex] = cell.PhoneNumber; + }; + } +// cell.PhoneLabel = phoneNumbers[indexPath.Row].Label.ToString ().Replace ("_$!<", "").Replace (">!$_", ""); +// cell.PhoneNumber = phoneNumbers[indexPath.Row].Value.ToString (); + cell.PhoneLabel = labels[indexPath.Row].Replace ("_$!<", "").Replace (">!$_", ""); + cell.PhoneNumber = numbers [indexPath.Row]; cell.SelectionStyle = UITableViewCellSelectionStyle.None; + + + + return cell; } @@ -298,13 +370,15 @@ namespace Example_SharedResources.Screens.iPhone.Contacts protected class EditablePhoneTableCell : UITableViewCell { // label and phone number text boxes - UITextField txtLabel = new UITextField(new RectangleF(10, 5, 110, 33)); - UITextField txtPhoneNumber = new UITextField(new RectangleF(130, 5, 140, 33)); - + public UITextField txtLabel = new UITextField(new RectangleF(10, 5, 110, 33)); + public UITextField txtPhoneNumber = new UITextField(new RectangleF(130, 5, 140, 33)); + // properties public string PhoneLabel { get { return txtLabel.Text; } set { txtLabel.Text = value; } } public string PhoneNumber { get { return txtPhoneNumber.Text; } set { txtPhoneNumber.Text = value; } } - + + public int dataIndex; + public EditablePhoneTableCell(string reuseIdentifier) : base(UITableViewCellStyle.Default, reuseIdentifier) { AddSubview(txtLabel); @@ -316,7 +390,11 @@ namespace Example_SharedResources.Screens.iPhone.Contacts txtPhoneNumber.ReturnKeyType= UIReturnKeyType.Done; txtPhoneNumber.BorderStyle = UITextBorderStyle.Line; txtPhoneNumber.ShouldReturn += (t) => { t.ResignFirstResponder(); return true; }; - } + + + } + + } #endregion