Bug in Ch. 22


#1

There seems to be a bug in Chapter 22. If you choose an inheritor that has a phone number and then go back and change the inheritor to a contact that does not have a phone number, the new inheritor will display with the old inheritor’s phone number. Anyone know how to fix? Thanks in advance for any help.


#2

Hi,

You could just set the attribute to a blank one before looking up the new details - then if it doesn’t have one it will stay blank.

in ItemDetailViewController

[code]- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)aPeoplePicker
shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
// Get the first and last name from the selected person
NSString *firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *lastName = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);

// Get all of the phone numbers for this selected person 
ABMultiValueRef numbers = ABRecordCopyValue(person, kABPersonPhoneProperty);


[editingPossession setInheritorNumber:@""];      //<--------------ADD THIS LINE



// Make sure we have at least one phone number for this person 
if (ABMultiValueGetCount(numbers) > 0) { 
    // Grab the first phone number we see 
    CFStringRef number = ABMultiValueCopyValueAtIndex(numbers, 0); 
    // Add that phone number to the possession object we are editing 
    [editingPossession setInheritorNumber:(NSString *)number]; 
    // Set the on screen UILabel to this phone number 
    [inheritorNumberField setText:(NSString *)number]; 
    
    // We used "Copy" to get this value, we need to manually release it 
    CFRelease(number); 
}

[/code]

HTH
Gareth


#3

Thanks for your response. I figured out how to resolve this and came back here to post the answer in case it might help someone else… Then I saw that a response had already been posted. I thought I’d be notified automatically about responses, but I didn’t receive any e-mail notification. Anyways, thanks a million for the answer. I’ll look around and see if I can figure out how to get e-mail notifications in the future.


#4

You also might want to update the Label.

else { [inheritorNumberField setText:@"N/A"]; }

just for feedback…

Is there a more elegant solution ?

thanks
Ian