Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UILabel地址标签为空,本地声明隐藏实例变量_Objective C - Fatal编程技术网

Objective c UILabel地址标签为空,本地声明隐藏实例变量

Objective c UILabel地址标签为空,本地声明隐藏实例变量,objective-c,Objective C,我是Xcode新手,我正在尝试让我的应用程序访问通讯簿,选择一个人,然后为这个人创建NSString值(名字、姓氏、组织、地址、电子邮件和电话号码)。我可以提取名字和姓氏、组织、输入的第一封电子邮件(最好显示所有电子邮件地址,并让用户选择),以及输入的第一个电话号码(同样,能够选择也很好),但此人的地址始终为空。我非常感谢您提供的任何帮助。此外,我不断收到本地声明隐藏实例变量警告-我不知道如何解决这些问题 #import "TACustomer.h" @interface TACustomer

我是Xcode新手,我正在尝试让我的应用程序访问通讯簿,选择一个人,然后为这个人创建NSString值(名字、姓氏、组织、地址、电子邮件和电话号码)。我可以提取名字和姓氏、组织、输入的第一封电子邮件(最好显示所有电子邮件地址,并让用户选择),以及输入的第一个电话号码(同样,能够选择也很好),但此人的地址始终为空。我非常感谢您提供的任何帮助。此外,我不断收到本地声明隐藏实例变量警告-我不知道如何解决这些问题

#import "TACustomer.h"

@interface TACustomer ()

@end

@implementation TACustomer

@synthesize custfirstName;
@synthesize custlastName;
@synthesize custOrganization;
@synthesize custEmail;
@synthesize custAddress;
@synthesize custphoneNumber;



- (IBAction)showPicker:(id)sender
{
    // Creating the Address Book Picker
    ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
    // Place the delegate of the picker to the control.
    picker.peoplePickerDelegate = self;

    // Showing the picker.
    [self presentModalViewController:picker animated:YES];

}



- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
    //assigning control back to the main controller.
    [self dismissModalViewControllerAnimated:YES];

}



- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{

    [self displayPerson:person];

    [self dismissModalViewControllerAnimated:YES];

    return NO;

}



- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
                            property:(ABPropertyID)property
                          identifier:(ABMultiValueIdentifier)identifier
{


    // Only inspect the value if it's an address.
    if (property == kABPersonAddressProperty)
    {

        //Set up an ABMultiValue to hold the address values; copy from a book record.
        ABMutableMultiValueRef multicustValue = ABRecordCopyValue(person, property);


        // Set up an NSArray and copy values into it.
        NSArray *thecustArray = (__bridge id)ABMultiValueCopyArrayOfAllValues(multicustValue);


        // Figure out which values we want and store the index.
        const NSUInteger customerIndex = ABMultiValueGetIndexForIdentifier (multicustValue, identifier);

        // Set up an NSDictionary to hold the contents of the array.
        NSDictionary *custDict = [thecustArray objectAtIndex:customerIndex];

        // Set up NSStrings to hold the keys and values. First, how many are there?
        const NSUInteger theCount = [custDict count];
        NSString * __unsafe_unretained keys[theCount];
        NSString *__unsafe_unretained values[theCount];

        // Get the keys and values from the CFDictionary.
        [custDict getObjects:values andKeys:keys];



        // Set the address label's text.
        NSString *customeraddress;
        customeraddress = [NSString stringWithFormat:@"%@, %@, %@, %@, %@",
                   [custDict objectForKey:(NSString *)kABPersonAddressStreetKey],
                   [custDict objectForKey:(NSString *)kABPersonAddressCityKey],
                   [custDict objectForKey:(NSString *)kABPersonAddressStateKey],
                   [custDict objectForKey:(NSString *)kABPersonAddressZIPKey],
                   [custDict objectForKey:(NSString *)kABPersonAddressCountryKey]];

        self.custAddress.text = customeraddress;


    }
        return NO;
}



- (void)displayPerson:(ABRecordRef)person
{

    // Get Customer First Name
    NSString* custfirstname = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonFirstNameProperty);

    self.custfirstName.text = custfirstname;


    // Get Customer Last Name
    NSString* custlastname = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonLastNameProperty);

    self.custlastName.text = custlastname;


    // Get Customer Organization
    NSString* custorganization = (__bridge_transfer NSString*)ABRecordCopyValue(person,kABPersonOrganizationProperty);

    self.custOrganization.text = custorganization;



    //Get Customer Email Address
    NSString* custemail = nil;
    ABMultiValueRef custemailAddresses = ABRecordCopyValue (person,kABPersonEmailProperty);

    if (ABMultiValueGetCount(custemailAddresses) > 0)
    {
        custemail = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(custemailAddresses, 0);

    } else
    {
        custemail = @"[None]";

    }
    self.custEmail.text = custemail;
    CFRelease(custemailAddresses);


    // Get Customer Phone Number
    NSString* custphone = nil;
    ABMultiValueRef phoneNumbers = ABRecordCopyValue (person,kABPersonPhoneProperty);

    if (ABMultiValueGetCount(phoneNumbers) > 0)
    {
        custphone = (__bridge_transfer NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, 0);

    } else
    {
        custphone = @"[None]";

    }
    self.custphoneNumber.text = custphone;
    CFRelease(phoneNumbers);


bundle:nil;

//[self.navigationController pushViewController:tempExamInfoView animated:YES];
}

@end

对于地址数据为空的问题,我没有答案

要消除“local declaration hides instance variable”警告,您需要使用不同的变量名,这些变量名与正在合成的属性名不冲突

例如,在
displayPerson:
中,您有一个局部变量
custfirstname
。因为它使用相同的名称作为属性,所以局部变量会隐藏正在合成的相同名称的实例变量


如果您想保留局部变量名,我相信也可以告诉
@synthesis
为它生成的实例变量使用不同的名称。我不熟悉语法,因此如果您想这样做,您必须自己查找。

请告诉我们错误发生在哪里,只需发布相关部分即可在设置为
self.custAddress.text
之前,是否可以尝试键入
customeraddress
。打印的值是多少?