Esempio n. 1
0
        void setupPicker()
        {
            picker               = new ABPeoplePickerNavigationController();
            picker.Delegate      = new PickerDelegate();
            picker.SelectPerson += delegate(object sender, ABPeoplePickerSelectPersonEventArgs e) {
                personViewer.DisplayedPerson = e.Person;
                picker.PushViewController(personViewer, true);
            };
            picker.PerformAction += delegate(object sender, ABPeoplePickerPerformActionEventArgs e) {
                var prop  = (ABMultiValue <string>)e.Person.GetProperty(e.Property);
                var email = prop[e.Identifier.Value].Value;
                SelectedValue.Email  = email;
                SelectedValue.Person = e.Person;
                picker.DismissModalViewControllerAnimated(true);
                this.NavigationController.PopViewControllerAnimated(false);
            };

            picker.Cancelled += delegate {
                picker.DismissModalViewControllerAnimated(true);
                this.NavigationController.PopViewControllerAnimated(false);
            };

            personViewer = new ABPersonViewController();
            personViewer.DisplayedProperties.Add(ABPersonProperty.FirstName);
            personViewer.DisplayedProperties.Add(ABPersonProperty.LastName);
            personViewer.DisplayedProperties.Add(ABPersonProperty.Email);
            personViewer.PerformDefaultAction += delegate(object sender, ABPersonViewPerformDefaultActionEventArgs e) {
                var prop  = (ABMultiValue <string>)e.Person.GetProperty(e.Property);
                var email = prop[e.Identifier.Value].Value;
                SelectedValue.Email  = email;
                SelectedValue.Person = e.Person;
                picker.DismissModalViewControllerAnimated(true);
                this.NavigationController.PopViewControllerAnimated(false);
            };
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Address Book Controllers";

            // displays the contact picker controller when the choose contact button is clicked
            btnChooseContact.TouchUpInside += (s, e) => {
                // create the picker control
                addressBookPicker = new ABPeoplePickerNavigationController();

                // in this case, we can call present modal view controller from the nav controller,
                // but we could have just as well called PresentModalViewController(...)
                NavigationController.PresentModalViewController(addressBookPicker, true);

                // when cancel is clicked, dismiss the controller
                // HACK: NavigationController.DismissModalViewControllerAnimated to NavigationController.DismissModalViewController
                addressBookPicker.Cancelled += (sender, eventArgs) => { NavigationController.DismissModalViewController(true); };

                // when a contact is chosen, populate the page with details and dismiss the controller
                addressBookPicker.SelectPerson += (object sender, ABPeoplePickerSelectPersonEventArgs args) => {
                    selectedPerson    = args.Person;
                    lblFirstName.Text = selectedPerson.FirstName;
                    lblLastName.Text  = selectedPerson.LastName;
                    // HACK: NavigationController.DismissModalViewControllerAnimated to NavigationController.DismissModalViewController
                    NavigationController.DismissModalViewController(true);
                };
            };

            // shows the view/edit contact controller when the button is clicked
            btnViewSelectedContact.TouchUpInside += (s, e) => {
                // if a contact hasn't been selected, show an alert and return out
                if (selectedPerson == null)
                {
                    new UIAlertView("Alert", "You must select a contact first.", null, "OK", null).Show();
                    return;
                }

                // instantiate a new controller
                addressBookViewPerson = new ABPersonViewController();

                // set the contact to display
                addressBookViewPerson.DisplayedPerson = selectedPerson;

                // allow editing
                addressBookViewPerson.AllowsEditing = true;

                // push the controller onto the nav stack. the view/edit controller requires a nav
                // controller and handles it's own dismissal
                NavigationController.PushViewController(addressBookViewPerson, true);
            };
        }
Esempio n. 3
0
 public static void PickContactPhoneNumber(UIViewController view, string currentValue, Action <string> picked)
 {
     PickContact(view, person =>
     {
         personViewer = new ABPersonViewController();
         personViewer.DisplayedPerson = person;
         personViewer.DisplayedProperties.Add(ABPersonProperty.FirstName);
         personViewer.DisplayedProperties.Add(ABPersonProperty.LastName);
         personViewer.DisplayedProperties.Add(ABPersonProperty.Phone);
         personViewer.PerformDefaultAction += delegate(object sender, ABPersonViewPerformDefaultActionEventArgs e) {
             var prop  = (ABMultiValue <string>)e.Person.GetProperty(e.Property);
             var phone = prop[e.Identifier.Value].Value;
             picked(phone);
         };
         picker.PushViewController(personViewer, true);
     });
 }
Esempio n. 4
0
 public static void PickContactPhoneNumber(UIViewController view, string currentValue, Action<string> picked)
 {
     PickContact (view, person =>
     {
         personViewer = new ABPersonViewController ();
         personViewer.DisplayedPerson = person;
         personViewer.DisplayedProperties.Add (ABPersonProperty.FirstName);
         personViewer.DisplayedProperties.Add (ABPersonProperty.LastName);
         personViewer.DisplayedProperties.Add (ABPersonProperty.Phone);
         personViewer.PerformDefaultAction += delegate(object sender, ABPersonViewPerformDefaultActionEventArgs e) {
             var prop = (ABMultiValue<string>)e.Person.GetProperty (e.Property);
             var phone = prop[e.Identifier.Value].Value;
             picked (phone);
         };
         picker.PushViewController (personViewer, true);
     });
 }
Esempio n. 5
0
        void ShowPersonViewController()
        {
            ABPerson[] people = addressBook.GetPeopleWithName("Appleseed");

            if (people != null && people.Length > 0)
            {
                ABPerson person = people [0];
                var      pvc    = new ABPersonViewController()
                {
                    DisplayedPerson = person,
                    AllowsEditing   = true
                };
                pvc.PerformDefaultAction += HandlePerformDefaultAction;

                NavigationController.PushViewController(pvc, true);
            }
            else
            {
                var alert = UIAlertController.Create("Error", "Could not find Appleseed in the Contacts application", UIAlertControllerStyle.Alert);
                alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Default, null));
                PresentViewController(alert, true, null);
            }
        }
Esempio n. 6
0
        void setupPicker()
        {
            picker = new ABPeoplePickerNavigationController ();
            picker.Delegate = new PickerDelegate ();
            picker.SelectPerson	+= delegate(object sender, ABPeoplePickerSelectPersonEventArgs e) {
                personViewer.DisplayedPerson = e.Person;
                picker.PushViewController (personViewer, true);
            };
            picker.PerformAction += delegate(object sender, ABPeoplePickerPerformActionEventArgs e) {
                var prop = (ABMultiValue<string>)e.Person.GetProperty (e.Property);
                var phone = prop[e.Identifier.Value].Value;
                SelectedValue.PhoneNumber = phone;
                SelectedValue.Person = e.Person;
                picker.DismissModalViewControllerAnimated (true);
                this.NavigationController.PopViewControllerAnimated (false);
            };

            picker.Cancelled += delegate {
                picker.DismissModalViewControllerAnimated (true);
                this.NavigationController.PopViewControllerAnimated (false);

            };

            personViewer = new ABPersonViewController ();
            personViewer.DisplayedProperties.Add (ABPersonProperty.FirstName);
            personViewer.DisplayedProperties.Add (ABPersonProperty.LastName);
            personViewer.DisplayedProperties.Add (ABPersonProperty.Phone);
            personViewer.PerformDefaultAction += delegate(object sender, ABPersonViewPerformDefaultActionEventArgs e) {
                var prop = (ABMultiValue<string>)e.Person.GetProperty (e.Property);
                var phone = prop[e.Identifier.Value].Value;
                SelectedValue.PhoneNumber = phone;
                SelectedValue.Person = e.Person;
                picker.DismissModalViewControllerAnimated (true);
                this.NavigationController.PopViewControllerAnimated (false);
            };
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            Title = "Address Book Controllers";

            // displays the contact picker controller when the choose contact button is clicked
            btnChooseContact.TouchUpInside += (s, e) => {
                // create the picker control
                addressBookPicker = new ABPeoplePickerNavigationController();

                // in this case, we can call present modal view controller from the nav controller,
                // but we could have just as well called PresentModalViewController(...)
                NavigationController.PresentModalViewController(addressBookPicker, true);

                // when cancel is clicked, dismiss the controller
                addressBookPicker.Cancelled += (sender, eventArgs) => { NavigationController.DismissModalViewControllerAnimated(true); };

                // when a contact is chosen, populate the page with details and dismiss the controller
                addressBookPicker.SelectPerson += (object sender, ABPeoplePickerSelectPersonEventArgs args) => {
                    selectedPerson = args.Person;
                    lblFirstName.Text = selectedPerson.FirstName;
                    lblLastName.Text = selectedPerson.LastName;
                    NavigationController.DismissModalViewControllerAnimated(true);
                };
            };

            // shows the view/edit contact controller when the button is clicked
            btnViewSelectedContact.TouchUpInside += (s, e) => {

                // if a contact hasn't been selected, show an alert and return out
                if(selectedPerson == null)
                {
                    new UIAlertView ("Alert", "You must select a contact first.", null, "OK", null).Show ();
                    return;
                }

                // instantiate a new controller
                addressBookViewPerson = new ABPersonViewController ();

                // set the contact to display
                addressBookViewPerson.DisplayedPerson = selectedPerson;

                // allow editing
                addressBookViewPerson.AllowsEditing = true;

                // push the controller onto the nav stack. the view/edit controller requires a nav
                // controller and handles it's own dismissal
                NavigationController.PushViewController (addressBookViewPerson, true);
            };
        }
		void ShowPersonViewController ()
		{
			ABPerson[] people = addressBook.GetPeopleWithName ("Appleseed");

			if (people != null && people.Length > 0) {
				ABPerson person = people [0];
				var pvc = new ABPersonViewController () {
					DisplayedPerson = person,
					AllowsEditing = true
				};
				pvc.PerformDefaultAction += HandlePerformDefaultAction;

				NavigationController.PushViewController (pvc, true);
			} else {
				var alert = UIAlertController.Create ("Error", "Could not find Appleseed in the Contacts application", UIAlertControllerStyle.Alert);
				alert.AddAction (UIAlertAction.Create ("Cancel", UIAlertActionStyle.Default, null));
				PresentViewController (alert, true, null);
			}
		}