我想在数组中或在保存之前合并两个对象

发布于 2024-08-19 15:21:01 字数 699 浏览 6 评论 0原文

我正在从 ABpeoplepickerNavcontroller 保存名字和姓氏,我想在保存到数组之前合并名字和姓氏,以便当我检索它时,它们会在一起。第一个代码是正在创建的对象:

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

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

这是我保存它的位置:

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

[array writeToFile:recipient atomically:NO];
[array release];

我可以在一行上保存添加两个对象吗?或者我可以在添加到数组之前合并对象吗?

谢谢,郑重声明……这个网站和帮助我的人都很棒。

迈克尔

I am saving the first and last name from ABpeoplepickerNavcontroller, I would like to merge the first and last name prior to saving into an array so that when i retrieve it, they would be together. The first code is the object being created:

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

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

Here's where I save it:

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

[array writeToFile:recipient atomically:NO];
[array release];

Can I save add two objects on one line? or Can I merge the objects prior to adding to array?

Thanks, and for the record...this site and the people who have helped me have been fantastic.

Michael

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

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

发布评论

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

评论(3

楠木可依 2024-08-26 15:21:01

我不确定你所说的合并是什么意思。如果要将一个字符串附加到另一个字符串,请执行以下操作:

NSString *joinedNamed = [NSString stringWithFormat:@"%@ %@", firstName.text, lastName.text]; 

I am not sure what you mean by merging. If you want to append one string to the other do the following:

NSString *joinedNamed = [NSString stringWithFormat:@"%@ %@", firstName.text, lastName.text]; 
叶落知秋 2024-08-26 15:21:01

您可以像这样使用stringByAppendingString

[array addObject:[firstName.text stringByAppendingString:lastName.text]];

You can use the stringByAppendingString like this:

[array addObject:[firstName.text stringByAppendingString:lastName.text]];

治碍 2024-08-26 15:21:01

来自 iPhone 通讯录编程指南:

“然而,在实际应用中,推荐使用 ABRecordCopyCompositeName 函数来显示一个人的全名。它将名字和姓氏按照用户喜欢的顺序排列,这提供了更统一的用户体验。”

这里的解决方案可以工作,但如果您只使用复合名称,您可能根本不需要这样做。

From the Address Book Programming Guide for iPhone:

"However, in actual applications, the function ABRecordCopyCompositeName is the recommended way to get a person’s full name to display. It puts the first and last name in the order preferred by the user, which provides a more uniform user experience."

The solutions here will work but it's something you may not need to do at all if you just use the composite name.

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