0

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);
    }

我错过了什么吗?

4

1 回答 1

0

如果其他人遇到类似问题,似乎已经解决了这个问题。

解决方案是完全关闭mac上的visual studio并重新打开它。最初,我正在停止该项目并重新构建。可能是一个错误,但我的更改没有被拾取。

一个简单的重新启动将其重新启动

于 2018-04-24T20:23:06.187 回答