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?
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.
Related
I have been told to do the following:
Implement contact add view like below and let him store in SQL table,
contacts will have Name, phone no of mobile, work , fax, email . view
should look like below:
My question:
Can you clarify me, should I use Addressbook or simply a custom view and a sql database to save data from that custom view? I mean both the options are open here?
You can not use address book to create custom content in your application.
So you should implement your custom view to collect information to store in your database (sqlite?)
If you are creating contact / modifying existing contact information, you can use address book framework.
Answer for the question in comment (how to go about for this kinda UI)
Yes, Have the grouped table view to get the desired background
Among the many possible solutions, here is the simplest one perhaps:
Have 2 sections in your table.
First section has a special kinda cell. Only one row in this section.
You can use Interface Builder to create the cell contents or you could build from code.
Second section contains similar cells. It can contain as many as the fields you need.
Just specify UITableViewCell's style to be UITableViewCellStyleValue2 and specify the values accordingly
I have created one Login Screen where user enter their mail id.
But i want to insert one functionality where it should list the mail id automatically when user type first character of mail id
There is one way. I don't know how much feasible it is. So the Idea is : You can store somewhere all the email id after log in success. For example in sqlite database. Now, Implement Notification center for "UITextFieldTextDidChangeNotification" and search for the character in database when user start typing in TextField and show UITableview underneath UITextField with match results (which start from entered character).
When user tap on any cell of Tablview hide tableview and take that cell label value in UITextField. That's it. Hope this logic work.
You can save the emaid id in UserDefaults & use it whereever you want
I am developing an App with information about a location. This information contains phone number, email address, address etc. A bit like the contact detail information of the iPhone itself.
Now my question. When I select a contact in my phonebook, I can select the phonenumber to call, select an emailaddress to mail and select the location information to view it in the maps of the iPhone. This is what I want to achieve.
I have searched google for this functionallity but I am probably searching for the wrong things.Can someone help me to achieve this functionallity?
Thanks!!!
//// Followup
Now I know that the stuff I want to add is possible, I have a followup question about this subject.
Does anyone know where I can find some examples about the actions for calling, mailing and location information? It would help me a lot...
Thnx!!
With kind regards,
Douwe
Here is the link for accessing address book details.
This example shows to display the first name, last name, instead you display phno.,email, location along with a button near ti it.
Then code in your button action to call, mail, view location respectively.
If you are using a UITableView, then tableView:didSelectRowAtIndexPath: will get sent to you (the table view delegate (usually the table view controller)) each time the user presses a row in your table.
In the Contacts app all phone numbers/emails/addresses for that contact are grouped in their own "section". By reading the section from the indexPath using [indexPath section] you will get the index for the section (a NSInteger).
Using your own app logic you can use that index to determine if the user pressed something in the phone/mail/address section. Now that you know what kind of information the user tapped on you can make the right thing (initiate a phone call/send an email/give directions)
Continuing using the same indexPath you can get the exact table view cell that the user clicked on by using [indexPath row]. Now you can send that information (say a phone number) to you own code to handle that information (initiate a phone call).
(Hope it helped, it was my first answer on StackOverflow)
I am looking for a good pattern for performing basic property editing via a modal view on the iPhone.
Assume I am putting together an application that works like the Contacts application. The "detail" view controller displays all of the contact's properties in a UITableView. When the UITableView goes into edit mode a disclosure icon is displayed in the cells. Clicking a cell causes a modal "editor" view controller to display a view that allows the user to modify the selected property. This view will often contain only a single text box or picker. The user clicks Cancel/Save and the "editor" view is dismissed and the "detail" view is updated.
In this scenario, which view is responsible for updating the model?
The "editor" view could update the property directly using Key-Value Coding. This appears in the CoreDataBooks example. This makes sense to me on some level because it treats the property as the model for the editor view controller.
However, this is not the pattern suggested by the View Controller Programming Guide. It suggests that the "editor" view controller should define a protocol that the "detail" controller adopts. When the user indicates they are done with the edit, the "detail" view controller is called back with the entered value and it dismisses the "editor" view. Using this approach the "detail" controller updates the model. This approach seems problematic if you are using the same "editor" view for multiple properties since there is only a single call-back method.
Would love to get some feedback on what approach works best.
I don't think any of the Apple examples (or anyone else's) actually show you how to structure an entire real world application. Instead, each example is just a test harness which shows you how to use one particular feature of the API but pays no attention to how that feature really integrates with anything else. Data models are given particularly short shift.
I prefer a design in which the data model is the spine of the application upon which hands all the view-controller/view pairs. The view controllers do not communicate with each other directly but instead communicate through the data model. The data model tracks what information the app is currently working on and therefore what data each particular view controller needs at any given time.
Let's use a contact manager type apps as an example. The basic of the data model would be a list of contact objects each of which in turn would hold attributes of a contact. The data model would completely control access to the data and monitors which data was currently being used. The UI is hierarchal such that the user first sees a list of all contacts in a masterView, then the details of each contact in a contactDetailView and then can edit each contact attribute in a custom attribute edit view for each type of data so there is a nameEditView, a phoneDetailView, an emailEditView etc. Each has a paired view controller masterVC, contactDetailVC, nameEditVC etc.
The to build it's tableview, the masterVC ask the data model for the number of contacts, their divisions into sections and then request each particular contact object at each particular index path so it can display a table. When the user selects a table row, the masterVC tells the data model which contact object was selected by sending it the index. Then the masterVC pushes the contactDetailVC. It does nothing else.
When the contactDetailVC activates, it ask the data model for the currently active Contact object. It doesn't know or care how the current contact was selected nor even which view/VC preceded it. The data model returns the currently active contact. When the user selects a field, the contactDetailVC tells the data model which attribute of the contact was selected and then pushes the proper editorVC onto the stack.
When the editorVC loads it ask for the data model for the current contact and the current attribute being edited. It doesn't know or care how the current contact attribute was selected nor even which view/VC preceded it. When the user makes a change, it ask the data model to save the change (the data model can refuse if verification fails for some reason) and then pops itself.
Internally, I like to implement the data model in two parts each managed by separate object. One is the abstracted data manager itself in this case a Core Data stack. The second is an user defaults manager that tracks the actual state of operations in the data model and saves them to user defaults. A master object holds these objects as attributes and serves as the interface of the data model.
This type of model makes it easy to suspend, resume or restart the application back to its previous state. Since each view/VC is self contained, when you restart the app, you just push all the views on the stack without animation and the last one pushed pops up fully populated with data even though the user chose nothing in the previous views and indeed did not even see them.
It also protects the user from data loss in the event of a crash since each VC saves its data and the app state every time it pushes or pops. It's easy to add additional view/VC because each VC only has to know about and communicate with the data model instead of bunch of other VC. It makes the components of the app easy to use in different versions of the app or in different apps altogether.
Edit:
Do you just hard code some if
statements to pair up the attributes
with the correct editor, or are you
doing something more dynamic based on
the entity/attribute metadata?
In most the most common design, the Contact entity could have a variable number of phone#s, emails or other data fields so each attribute would actually be a separate entity and the Contact would have a relationships pointing to those entities. When the user selected that contact to edit in the ContactDetailView, the data-model would simply mark the NSManagedObject representing the desired attribute of the contact. It could do so by setting an attribute like "lastChosenAttribute" or storing the URI for the object. When the editor view loaded it would be hard coded to ask the data-model for the "lastChosenAttribute" and would receive an NSManagedObject for a phone#, email etc. The editor would make changes to that object and they would be automatically saved back into the contact.
For data that is singular, such as a name or name components, the data-model would provide the editorVC with the contact entity and the editorVC would be hard coded to ask the contact object for that specific attribute.
It's a tough call--the View Controller Guide recommendation seems cleaner conceptually, but the other method can be easier, especially if you're using Core Data. To give a blanket generalized opinion, I would say use your first method if you're using Core Data, since managed objects inherently have their own context and can update themselves (and classes such as NSFetchedResultsController can automatically respond to updates).
If you're not using Core Data, I would go with the "official" recommendation, since it makes it easier to manage updated properties manually. As to the concern about multiple properties, it's certainly possible to have multiple delegate methods and call the appropriate one. For instance:
//if property is an address
if ([self.delegate respondsToSelector:#selector(editorView:didUpdateAddress:)])
[self.delegate editorView:self didUpdateAddress:theAddress];
//if property is a name
if ([self.delegate respondsToSelector:#selector(editorView:didUpdateName:)])
[self.delegate editorView:self didUpdateName:theName];
This could get hard to manage, though--you'd probably want to have an abstract superclass for properties, or something along those lines.
I would like to achive the same functinoanlity in the UITextField control as Google search web site (which uses Ajax for this): as user start typing, list of suggestion searches is shown. Then more letteres you type, suggestion list changes.
So imaging I have array of words:
Apple
Abc
Aman
As user types A, all thress suggesions are shown, if user type one more letter p, then Apple is suggested.
How would I do something like this? Mail type of applicatins do it, when receipent name is typed in the To: edit control
I guess I can use UITableView with the search, is it correct approach?
You want a UISearchBar. It's designed to do exactly this. Its delegate provides the list to search and present.