z2k
z2k

Reputation: 10410

Only display/use the "To: " field from MFMailComposeViewController

In my app I have the need to allow the user to assemble a "To list" of emails. The built in mail composer has exactly what I want as far as being able to select contacts. It has a drop list that displays potential matched contacts from what you are typing. However this is not for sending an email, therefor I dont' want the CC, Subject, and Body controls.

Is just the "To" field available in a control somehow? I don't see really how to do this without writing quite a bit of code.

I suppose I could always bring up a mail composer and then another view to cover up the rest of the form, but I'd rather leverage just the To field.

Is this possible?

Upvotes: 0

Views: 125

Answers (1)

z2k
z2k

Reputation: 10410

Maybe this will help someone else. After much searching I didn't see any way to leverage the To: field only. I ended up coding my own set of view controllers to copy the actions and behavior. I made the following classes:

  • Contact (string properties for first name, last name, and email)
  • Contacts (class methods to create an NSArray of Contact objects in various formats)
  • ContactFormViewController (analog to the mail composer's To: field)
  • ContactTableViewController (displays a list of all contacts with a scrubber)

Inside Contacts class, I used ABAddressBookRequestAccessWithCompletion to create an NSArray of Contact* objects, sorting the array as I construct it.

I then have two view controllers, just like the mail composer.

On the first view controller, there is a UITextField to type an email address or name into, a UITableView to display contacts that match the input string, and a UIScrollView which I add UIButtons to each time a contact is selected in the table. Each editingChanged event on the UITextView creates/updates the datasource to the UITableView. There are also two more UIButtons. One to add a manually typed email address to the list selected contacts (this button is only visible if the text input matches an emiail regex), and the other button is to show the UITableViewController if the user would rather browser to contacts than type them in and pick results.

Upvotes: 1

Related Questions