xamarin 的绝对初学者。按照以下教程尝试,只需单击一个按钮即可显示联系人列表,选择一个联系人,然后在屏幕上显示名字、姓氏和地址。 https://github.com/xamarin/recipes/tree/master/Recipes/ios/shared_resources/contacts/choose_a_contact
设法获取要显示的名字和姓氏,但无法获取地址。不断收到错误
Foundation.MonoTouchException: Objective-C exception thrown. Name: CNPropertyNotFetchedException Reason: A property was not requested when contact was fetched.
在
contanct.PostalAddresses
这是代码片段:-
partial void UIButton197_TouchUpInside(UIButton sender)
{
// Create a new picker
var picker = new CNContactPickerViewController();
// Select property to pick
picker.DisplayedPropertyKeys = new NSString[] { CNContactKey.GivenName, CNContactKey.FamilyName, CNContactKey.PostalAddresses };
// Respond to selection
var pickerDelegate = new ContactPickerDelegate();
picker.Delegate = pickerDelegate;
pickerDelegate.SelectionCanceled += () => {
SelectedContact1.Text = "";
};
pickerDelegate.ContactSelected += (contact) => {
SelectedContact1.Text = contact.GivenName;
SelectedContact2.Text = contact.FamilyName;
SelectedContact3.Text = contact.PostalAddresses
};
pickerDelegate.ContactPropertySelected += (property) => {
SelectedContact1.Text = property.Value.ToString();
};
// Display picker
PresentViewController(picker, true, null);
}
我错过了什么吗?