将 addressbookUI 数据保存到数组

发布于 2024-08-17 15:57:07 字数 1489 浏览 8 评论 0原文

我正在尝试将 kABFirstNamePropert、kABLastNameProperty 和 kABAddressProperty 全部保存到数组中以便稍后调用,我只是不明白,任何人都可以帮我一把或为我指出正确的方向吗?谢谢。我在这方面是个超级菜鸟。

用于命名字符串:

// setting the first name
firstName.text = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);

// setting the last name
lastName.text = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);

用于设置地址标签:

NSString *address;
    address = [NSString stringWithFormat:@"%@, %@, %@, %@ %@",
               [theDict objectForKey:(NSString *)kABPersonAddressStreetKey],
               [theDict objectForKey:(NSString *)kABPersonAddressCityKey],
               [theDict objectForKey:(NSString *)kABPersonAddressStateKey],
               [theDict objectForKey:(NSString *)kABPersonAddressZIPKey],
               [theDict objectForKey:(NSString *)kABPersonAddressCountryKey]];

    self.addressLabel.text = address;

保存数组: 我所拥有的不起作用。 ;(

- (IBAction)saveData {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *recipient = [NSString stringWithFormat:@"%@/arraySaveFile", documentsDirectory];

    NSMutableArray *array = [[NSMutableArray alloc] init];
    [array addObject:firstName];
    [array addObject:lastName];
    [array addObject:addressLabel];

    [array writeToFile:recipient atomically:NO];

}

I'm trying to save the kABFirstNamePropert, kABLastNameProperty and kABAddressProperty all saved into an array for recall later, I'm just not getting it, can anyone lend me a hand or point me in the right direction? Thanks. I'm a super NOOb on this.

For the naming the strings:

// setting the first name
firstName.text = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);

// setting the last name
lastName.text = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);

For setting the addressLabel:

NSString *address;
    address = [NSString stringWithFormat:@"%@, %@, %@, %@ %@",
               [theDict objectForKey:(NSString *)kABPersonAddressStreetKey],
               [theDict objectForKey:(NSString *)kABPersonAddressCityKey],
               [theDict objectForKey:(NSString *)kABPersonAddressStateKey],
               [theDict objectForKey:(NSString *)kABPersonAddressZIPKey],
               [theDict objectForKey:(NSString *)kABPersonAddressCountryKey]];

    self.addressLabel.text = address;

Saving the Array: What I have that's not working. ;(

- (IBAction)saveData {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *recipient = [NSString stringWithFormat:@"%@/arraySaveFile", documentsDirectory];

    NSMutableArray *array = [[NSMutableArray alloc] init];
    [array addObject:firstName];
    [array addObject:lastName];
    [array addObject:addressLabel];

    [array writeToFile:recipient atomically:NO];

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染火枫林 2024-08-24 15:57:07

这:

[array addObject:firstName]; 

需要是:

[array addObject:firstName.text];

谢谢大家。

This:

[array addObject:firstName]; 

needed to be:

[array addObject:firstName.text];

Thanks Everyone.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文