public void ShowContact(NavigationPage page) { var key = DateTime.Now.ToString(); var newPersonController = new ABNewPersonViewController(); var person = new ABPerson(); person.FirstName = "John " + key; person.LastName = "Doe" + key; newPersonController.Title = "This is a test"; newPersonController.DisplayedPerson = person; UINavigationController nav = null; foreach (var vc in UIApplication.SharedApplication.Windows[0].RootViewController.ChildViewControllers) { if (vc is UINavigationController) { nav = (UINavigationController)vc; } } newPersonController.NewPersonComplete += (object sender, ABNewPersonCompleteEventArgs e) => { nav.DismissModalViewController(true); }; nav.PresentModalViewController(new UINavigationController(newPersonController), true); }
void ShowNewPersonViewController() { var npvc = new ABNewPersonViewController(); npvc.NewPersonComplete += HandleNewPersonComplete; var navigation = new UINavigationController(npvc); PresentViewController(navigation, true, null); }
public override void ViewDidLoad() { base.ViewDidLoad(); Title = "How to Create a Contact"; View.BackgroundColor = UIColor.White; _createContact = UIButton.FromType(UIButtonType.RoundedRect); _createContact.Frame = new CGRect(10, 60, 300, 50); _createContact.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; _createContact.SetTitle("Create a Contact", UIControlState.Normal); _contactName = new UILabel { Frame = new CGRect(10, 120, 300, 50) }; _contactName.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; View.AddSubviews(_createContact, _contactName); _newPersonController = new ABNewPersonViewController(); _createContact.TouchUpInside += (sender, e) => { var person = new ABPerson(); person.FirstName = "John"; person.LastName = "Doe"; _newPersonController.DisplayedPerson = person; NavigationController.PushViewController(_newPersonController, true); }; _newPersonController.NewPersonComplete += (object sender, ABNewPersonCompleteEventArgs e) => { if (e.Completed) { _contactName.Text = String.Format("new contact: {0} {1}", e.Person.FirstName, e.Person.LastName); } else { _contactName.Text = "cancelled"; } NavigationController.PopViewController(true); }; }
public override void ViewDidLoad() { base.ViewDidLoad (); Title = "How to Create a Contact"; View.BackgroundColor = UIColor.White; _createContact = UIButton.FromType (UIButtonType.RoundedRect); _createContact.Frame = new CGRect (10, 60, 300, 50); _createContact.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; _createContact.SetTitle ("Create a Contact", UIControlState.Normal); _contactName = new UILabel{Frame = new CGRect (10, 120, 300, 50)}; _contactName.AutoresizingMask = UIViewAutoresizing.FlexibleWidth; View.AddSubviews (_createContact, _contactName); _newPersonController = new ABNewPersonViewController (); _createContact.TouchUpInside += (sender, e) => { var person = new ABPerson (); person.FirstName = "John"; person.LastName = "Doe"; _newPersonController.DisplayedPerson = person; NavigationController.PushViewController (_newPersonController, true); }; _newPersonController.NewPersonComplete += (object sender, ABNewPersonCompleteEventArgs e) => { if (e.Completed) { _contactName.Text = String.Format ("new contact: {0} {1}", e.Person.FirstName, e.Person.LastName); } else { _contactName.Text = "cancelled"; } NavigationController.PopViewController (true); }; }
public override void ViewDidLoad() { base.ViewDidLoad(); Title = "New and Unknown Contacts"; // shows the create new contact screen when the button is clicked btnCreateNewContact.TouchUpInside += (s, e) => { // instantiate a new ABNewPersonViewController addressBookNewPerson = new ABNewPersonViewController(); // create a person from the fields on the screen so we can prepopulate the // controller with data ABPerson person = new ABPerson(); person.FirstName = txtFirstName.Text; person.LastName = txtLastName.Text; // prepopulate the controller with the person addressBookNewPerson.DisplayedPerson = person; // push the controller onto the nav stack NavigationController.PushViewController(addressBookNewPerson, true); // wire up the new person complete handler to pop the controller off the stack addressBookNewPerson.NewPersonComplete += (object sender, ABNewPersonCompleteEventArgs args) => { // if the "done" button was clicked, rather than cancel if (args.Completed) { // show an alert view with the new contact ID new UIAlertView("Alert", "New contact created, ID: " + args.Person.Id.ToString(), null, "OK", null).Show(); } // pop the controller off the stack // HACK: NavigationController.PopViewControllerAnimated to NavigationController.PopViewController NavigationController.PopViewController(true); }; }; // btnPromptForUnknown.TouchUpInside += (s, e) => { // instantiate a new unknown person controller addressBookUnknownPerson = new ABUnknownPersonViewController(); // create a person from the fields on the screen so we can prepopulate the // controller with data ABPerson person = new ABPerson(); person.FirstName = txtFirstName.Text; person.LastName = txtLastName.Text; // prepopulate the controller with the person addressBookUnknownPerson.DisplayedPerson = person; // allow adding to address book addressBookUnknownPerson.AllowsAddingToAddressBook = true; // allow them to share the contact, make calls, click on urls, etc in the controller addressBookUnknownPerson.AllowsActions = true; // push the controller onto the nav stack NavigationController.PushViewController(addressBookUnknownPerson, true); // handle the person created event addressBookUnknownPerson.PersonCreated += (object sender, ABUnknownPersonCreatedEventArgs args) => { Console.WriteLine("PersonCreated event raised"); // this dialog can be cancelled out of as well, but there is no Completed property, so we // just have to do a null check if (args.Person != null) { // show an alert view with the new contact ID new UIAlertView("Alert", "New contact created, ID: " + args.Person.Id.ToString(), null, "OK", null).Show(); } }; // you can also handle the perform default action event to determine whether or not the action should be allowed // to be perfomed. //addressBookUnknownPerson.PerformDefaultAction += (object sender, ABPersonViewPerformDefaultActionEventArgs args) => { // if(args.Property == ABPersonProperty.Url) // { // args.ShouldPerformDefaultAction = false; // } //}; }; }
public void ShowAddContactController(UINavigationController navigationController, User user) { ABNewPersonViewController abController = new ABNewPersonViewController (); ABPerson person = new ABPerson (); KeyValuePair <string, string> namePair = GetFirstAndLastName (user); person.FirstName = namePair.Key; person.LastName = namePair.Value; if (!string.IsNullOrEmpty (user.Company)) { person.Organization = user.Company; } if (!string.IsNullOrEmpty (user.Phone)) { ABMutableMultiValue<string> phones = new ABMutableStringMultiValue(); phones.Add(user.Phone, ABPersonPhoneLabel.Main); person.SetPhones(phones); } if (!string.IsNullOrEmpty (user.Email)) { ABMutableMultiValue<string> emails = new ABMutableStringMultiValue(); emails.Add(user.Email, null); person.SetEmails(emails); } // Get any image from cache byte [] data = Engine.Instance.ImageCache.FindAny (user); if (data != null && data.Length > 0) { person.Image = NSData.FromArray(data); } abController.DisplayedPerson = person; abController.NewPersonComplete += delegate { navigationController.PopViewControllerAnimated (true); }; navigationController.PushViewController (abController, true); if (OnAddContactCompleted != null) OnAddContactCompleted (); }
void ShowNewPersonViewController () { var npvc = new ABNewPersonViewController (); npvc.NewPersonComplete += HandleNewPersonComplete; var navigation = new UINavigationController (npvc); PresentViewController (navigation, true, null); }
public override void ViewDidLoad () { base.ViewDidLoad (); Title = "New and Unknown Contacts"; // shows the create new contact screen when the button is clicked btnCreateNewContact.TouchUpInside += (s, e) => { // instantiate a new ABNewPersonViewController addressBookNewPerson = new ABNewPersonViewController (); // create a person from the fields on the screen so we can prepopulate the // controller with data ABPerson person = new ABPerson (); person.FirstName = txtFirstName.Text; person.LastName = txtLastName.Text; // prepopulate the controller with the person addressBookNewPerson.DisplayedPerson = person; // push the controller onto the nav stack NavigationController.PushViewController (addressBookNewPerson, true); // wire up the new person complete handler to pop the controller off the stack addressBookNewPerson.NewPersonComplete += (object sender, ABNewPersonCompleteEventArgs args) => { // if the "done" button was clicked, rather than cancel if(args.Completed) { // show an alert view with the new contact ID new UIAlertView ("Alert", "New contact created, ID: " + args.Person.Id.ToString(), null, "OK", null).Show(); } // pop the controller off the stack // HACK: NavigationController.PopViewControllerAnimated to NavigationController.PopViewController NavigationController.PopViewController(true); }; }; // btnPromptForUnknown.TouchUpInside += (s, e) => { // instantiate a new unknown person controller addressBookUnknownPerson = new ABUnknownPersonViewController (); // create a person from the fields on the screen so we can prepopulate the // controller with data ABPerson person = new ABPerson (); person.FirstName = txtFirstName.Text; person.LastName = txtLastName.Text; // prepopulate the controller with the person addressBookUnknownPerson.DisplayedPerson = person; // allow adding to address book addressBookUnknownPerson.AllowsAddingToAddressBook = true; // allow them to share the contact, make calls, click on urls, etc in the controller addressBookUnknownPerson.AllowsActions = true; // push the controller onto the nav stack NavigationController.PushViewController (addressBookUnknownPerson, true); // handle the person created event addressBookUnknownPerson.PersonCreated += (object sender, ABUnknownPersonCreatedEventArgs args) => { Console.WriteLine ("PersonCreated event raised"); // this dialog can be cancelled out of as well, but there is no Completed property, so we // just have to do a null check if(args.Person != null) { // show an alert view with the new contact ID new UIAlertView ("Alert", "New contact created, ID: " + args.Person.Id.ToString (), null, "OK", null).Show (); } }; // you can also handle the perform default action event to determine whether or not the action should be allowed // to be perfomed. //addressBookUnknownPerson.PerformDefaultAction += (object sender, ABPersonViewPerformDefaultActionEventArgs args) => { // if(args.Property == ABPersonProperty.Url) // { // args.ShouldPerformDefaultAction = false; // } //}; }; }