iOS Development-No. 02-UI Advanced-08-Personal Address Book

Source: Internet
Author: User

Implementation: Private Address Book




Source code: Click to open the link


1. Implementation requirements


1> a jump between multiple controllers

2> data transfer between controllers

3> Data storage


2, login interface to the contact list interface implementation Ideas


2.1 Login Interface Setup


1> add a navigation controller to the storyboard, set the root controller, and set the title of the navigation bar

2> Build Login Interface

Note 1: Set the Uitextfield placeholder and the Clear text button

NOTE 2: Set the password Uitextfield the dark text

Note 3: Remember password Uilabel and switches as well as automatic login Uilabel and switches are placed in a uiview for easy layout and management

Note 4: The login button does not allow user interaction by default






2.2 Contact Interface Setup


1> Interface Controller for Uitableviewcontroller

2> Login Interface Controller Login button, connect jump to contact controller, and set the login interface navigation bar title, left item (logout), right (plus)


2.3 Initial implementation of login interface


Note: In development, a module corresponds to a controller

1> Adding a custom controller Hmloginviewcontroller, associating the login controller

2> Handle Login interface logic, monitor text box content change

Note: Three ways to listen for text box content---Important

1. Uitextfield Agent






Note: When using the proxy method above, can only get the contents of the previous text box, cannot get the last content of the input text box, that is: when the input a, print is empty, then enter B, print a, so in this case can not immediately get all the contents of the Account text box, cannot use this method


2. Nsnotificationcenter (more troublesome)




3. AddTarget (Simple)--- uitextfield inherit from Uicontrol, so you can addTarget






3> Remember Password and automatic login switch processing: Cancel Remember password, you must also cancel automatic login, turn on automatic login, also must open remember password




4> the Logout button processing of the contact interface

Note: In iOS8 above, Uiactionsheet has been canceled, use Uialertcontroller




5> Login button Handling

Note: Since the previous direct on the login button to jump to the contact controller, so automatically jump, can not determine whether the account and password is correct


2.4 Segue (used as a jump between controllers)---important












2.5 Login interface to make changes---important


1> Set the login interface to jump to the contact interface for manual segue

2> login response to determine the account number and password, in the program began to manually determine whether the login button can click, direct bar with TextChange method can

Note 1: If the use of Uialertview, then the pop-up account password is not correct after the manual cancellation, not conducive to user experience

Note 2: Third party framework mbprogresshud (cue box function)

Note 3: Add GCD delay operation (imitate the network of the actual application to determine the password is correct)

Note 4: Add masks, when logged in, prevent users from clicking, using Mbprogresshud




3, contact list interface to add contact interface implementation Ideas


3.1 Add a contact screen build


1> controller jump without judgment, direct automatic segue can

2> Building Interface


3.2 Adding a contact interface implementation


1> Custom controller Hmaddviewcontroller, associating

2> Add a property member, the input is similar to the login interface

3> Monitor Add button event response, jump to contact list interface, preliminary test


3.3---Important for the transfer of values between controllers


1>---The previous controller is passed to the next controller---take advantage of segue

1. Performseguewithidentifier: Principle of implementation






2. Set the title of the contact interface to login interface account (Shun Chuan)




2> Reverse Transmission ---- the next controller is passed to the previous controller

For example: the information that will be added to the contact interface is passed to the previous controller (contact list) display

1. Method One: Add a property to the next controller, point to the previous controller




A. Add a property to the Add contact controller, point to the Contact List controller, assign a value to the contact list controller after clicking the Add button




B. In the previous step, when the contact list controller jumps to add a contact controller, it gets the target controller (add contact Controller) and assigns a value to its properties (point to the contact list controller)




Note: The above implementation of the callback method is too high coupling, contact list controller and add contact controller who can not leave who, once a controller is not, another controller can not be used, is not recommended.


2. Method Two: Agent---The last controller becomes the agent of the next control

A. Customizing a model (name + phone), adding a Quick Create model method, creating a model after clicking Add

B. Customizing the agent to add a contact controller




C. Notify the agent after clicking the Add button




D. In the contact list controller, ready to jump to add contact controller (this step can get the target controller), set the agent for Add contact Controller to self

E. Add a mutable array to the contact list, save the above model, and lazy load

F. Implementing a proxy




G. Data source methods for implementing a contact list controller (inherited from Uitableviewcontroller)




3.4 Add a contact screen to automatically jump out of the keyboard


Primarily to appear when the view is displayed, do not load the view in the finished (viewdidload)




4. Contact List interface Click on the contact to jump to the editing interface


4.1 Editing Interface Setup


1> Contact List Cell Direct auto Segue to edit interface




Note 1: It is not possible to jump at this time, because the previous cell was created manually in the TableView datasource method, not created from storyboard, so the drag line in the storyboard cannot jump, You need to set the cell's identity in Storyboard!!!

NOTE 2: Because the agent has been set in the contact list before the Prepareforsegue method to add contacts, and each jump will call the method, when the direct click on the cell jump will cause the program to crash, so you need to add to the method of segue judgment, Decide which controller to jump to!!!




Note 3: If the cell is loaded from storyboard, it will be automatically loaded from the cache pool, no need to determine if the cell exists, the code in the box is not written!!!




4.2 Editing Interface Implementation


1> custom Editing interface Controller, associating

2> passing data from the contact List controller cell to the Edit interface controller (Shun Chuan)




3> displaying the data in the model to the editing interface

Note: Because the Prepareforsegue: method is called before the jump, so it is not possible to assign a value in the model setter method of the editing interface, display the data, the editing interface is still not displayed, due to lazy loading, the control will not be generated, the data will not be displayed on the control, Instead, the data should be displayed in the Viewdidload method of the modulo editing interface.

3> change the Edit interface Uitextfield the Clear button appears as Edit

4> Monitor Edit button response event, the main need to listen to two Uitextfield content Change event (the same login interface), determine whether the Save button to enable




5> Monitor Save button response event, need to return data, update contact list, use Agent




Note: The editing interface proxy is set to the contact list, the implementation of direct Reloaddata in the agent can be, because the contact list model and editing interface model point to the same piece of memory!!!


5, custom cell---cell separation line processing


5.1 Removing the UITableView separator line




Note: The above method will remove the separation line, in the actual use of the Cell when there is content, the divider line is displayed, and there is no divider when there is no content.


5.2 Custom Cell


1> Customizing a Cell

Note: Because the cell is loaded from storyboard, you need to bind the cell ID (previously bound), and the associated cell class






Adding class methods and models and their setter methods in the 2> cell, you simply pass the model in the TableView

3> adding a separator line to the cell (UIView)




Note: You cannot set the location for divide in awakefromnib because the cell's location is right tableview, and awakefromnib is called when the cell is loaded, You should set the divider position when the cell location is TableView, that is, set the position in Layoutsubviews!!!



iOS Development-No. 02-UI Advanced-08-Personal Address Book

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.