0

I use the TTMessageController from Three20 to display a view that is similar to the iPhone SMS application containing a recipient picker.

Currently I am able to autosearch contacts and to browse them by clicking on the + button:

enter image description here

However I have a problem to apply the selected contact to the recipient field. TTMessageController implements the addRecipient method but I am not sure how to use it.

In my controller class that extends TTMessageController I have following method which is triggered when a contact is selected, so addRecipient has to go here somewhere:

- (BOOL)peoplePickerNavigationController: 
                (ABPeoplePickerNavigationController *)peoplePicker
                shouldContinueAfterSelectingPerson:(ABRecordRef)person{
    //dismiss the contact selector
    [self dismissModalViewControllerAnimated:NO];
    return NO;
}

Any idea how to add the recipient in that method?

DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601

1 Answers1

1

Add a single item from your datasource to the recipient field. So if your datasource has an array of strings (names) you call addRecipient: with a string. The index is where you want to insert the recipient in the field.

Post your datasource implementation and I will completely your code.

unexpectedvalue
  • 6,079
  • 3
  • 38
  • 62
  • http://pastebin.com/eS6EgShL this ismy TTMessageController implementation. Search in the code for @test, test is added to the picker field so far, but I want the selected person to be added. I only want only ONE recipient to be added, so when the user clicks on add, the old recipient should be deleted – DarkLeafyGreen Apr 02 '11 at 15:29
  • AddressBookDataSource is the relevant class. I think you will need to override TTMessageController's addRecipient and call removeAllCells on the TTPickerTextField to clear it. – unexpectedvalue Apr 02 '11 at 15:43
  • AddressBookDataSource implemetation is from the answer to this question http://stackoverflow.com/questions/5374684/how-to-use-three20-ttmessagecontroller – DarkLeafyGreen Apr 02 '11 at 15:46
  • Override the addRecipient if you want only 1 recipient. – unexpectedvalue Apr 02 '11 at 16:17
  • I managed that using NSString *firstName = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty) ; NSString *surname = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty) ; thank you – DarkLeafyGreen Apr 02 '11 at 17:05