将 addressbookUI 数据保存到数组
我正在尝试将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这:
需要是:
谢谢大家。
This:
needed to be:
Thanks Everyone.