2010-01-15 78 views
0

我試圖挽救kABFirstNamePropert,kABLastNameProperty和kABAddressProperty所有保存到召回的數組後,我只是沒有得到它,任何人都可以借我的手或點我在正確的方向?謝謝。我是一個超級NOOB。保存addressbookUI數據到一個數組

對於命名的字符串:

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

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

用於設置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; 

保存數組:我有什麼是不工作。 (

- (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]; 

} 

回答

1

此:

[array addObject:firstName]; 

需要的是:

[array addObject:firstName.text]; 

謝謝大家