iOS development UI Chapter-Implement a private Address Book small application (i)-Top of the text

Source: Internet
Author: User
Tags notification center

Original http://www.cnblogs.com/wendingding/p/3773603.html

iOS development UI chapter-Implementing a private Address Book applet (i)

First, the main content of the completion of this part

1. Interface Construction

2. Function description

(1). The login button interacts only when the account and password input boxes have values

(2). When you uncheck the Remember password, the automatic login button is also canceled, and when the auto-login button is checked, the Remember Password button is also checked together.

(3). Click the login, pop-up masks, the interface is not interactive, the program can easily determine whether the account and password is correct, if not correct to give the corresponding prompt, if correct, jump to the contact list interface.

II. implementation process and code

Project file structure diagram and interface building

Implementation code:

YYLOGINVIEWCONTROLLER.M file

  1//2//Yyloginviewcontroller.m3//01-Personal Address Book (login Page Setup)4//5//Created by Apple on 14-6-6.6//Copyright (c) 2014 itcase. All rights reserved.7//87 mImport"YYloginViewController.h "10 #Import"Mbprogresshud+nj.h "11@interface Yyloginviewcontroller ()13/** 14 * Account input Box 15 */16@property (Weak, nonatomic) Iboutlet Uitextfield *numberfield;17/** 18 * Password input box 19 */20@property (Weak, nonatomic) Iboutlet Uitextfield *pwdfield;21st/** 22 * Login Button 23 */24@property (Weak, nonatomic) Iboutlet UIButton *loginbtn;25/** 26 * Remember password 27 */28@property (Weak, nonatomic) Iboutlet Uiswitch *rempwdswitch;29/** 30 * Automatic Login 31 */32@property (Weak, nonatomic) Iboutlet Uiswitch *autologinswitch;33/** 34 * Remember Password button 35 */-(Ibaction) Rempwdchange: (ID) sender;37/** 38 * Auto Login button 39 */-(Ibaction) Autologinchange: (ID) sender;41/** 42 * Click event for Login button 43 */-(Ibaction) Loginbtnonclick: (ID) sender;45@end47@implementation Yyloginviewcontroller4950-(void) Viewdidload51 {52 [Super Viewdidload];5354//Change of listening text input box55//1. Get Notification CenterNsnotificationcenter *center=[nsnotificationcenter Defaultcenter];57//2. Register for monitoring58//Note: Be sure to write the notice to the Publisher, otherwise if there is more than one text input box on the interface, it will respond59//Uitextfieldtextdidchangenotification Listening Events: The contents of the Text input box change60//Self.numberfield: Listening objects61//TextChange: The method that is called when an event occurs[Center Addobserver:self selector:@selector (TextChange) name:uitextfieldtextdidchangenotification Object:self.numberField];[Center Addobserver:self selector:@selector (TextChange) name:uitextfieldtextdidchangenotification Object:self.pwdField];64}656667//Listen for the status of the text input box and let the login button's state become interactive when there are values in the two text input boxes68-(void) TextChange69 {70//if (self.numberfield.text.length>0&&self.pwdfield.text.length>0) {71//Self.loginbtn.enabled=yes;72//}else73//This is mainly for data-back-deletion74//Self.loginbtn.enabled=no;7576//Can be rewritten as the following notationSelf.loginbtn.enabled= (self.numberfield.text.length>0&&self.pwdfield.text.length>0);78}79-(Ibaction) Rempwdchange: (ID) Sender {81//1. Determine if the password is remembered82//2. If you cancel remembering your password, you can also cancel automatic login83if (Self.rempwdswitch.ison==no) {84//Self.autologinswitch.on=no;85//animating effects[Self.autologinswitch Seton:no Animated:yes];87}88}89-(Ibaction) Autologinchange: (ID) Sender {91//1. Decide whether to log in automatically92//2. If you log in automatically, remember the password93if (Self.autologinswitch.ison==yes) {94 [Self.rempwdswitch Seton:yes Animated:yes];95}96}-(Ibaction) Loginbtnonclick: (ID) Sender {98//Click the login button, prompt to load information, and to determine the account and password, if the correct jump to the new interface, if not correct, then display the prompt message99//Third-party frameworks are used here100//After clicking the login button, add a mask to prevent user action and prompt the user to sign in101 [Mbprogresshud showmessage:@"Trying to load ... "];102//Let the subsequent operation be executed after 3 seconds103 Dispatch_after (Dispatch_time (Dispatch_time_now, (int64_t) (3.0 * nsec_per_sec)), Dispatch_get_main_queue (), ^{104if (![ Self.numberField.text isequaltostring:@"YY "]) {105//After the login operation, remove the mask106 [Mbprogresshud Hidehud];107//Incorrect input account, prompt error message108 [Mbprogresshud showerror:@"The account entered does not exist! "];109Return110}111if (![ Self.pwdField.text isequaltostring:@"123 "]) {112//Input password is incorrect, prompt error message113 [Mbprogresshud Hidehud];[Mbprogresshud showerror:@"The password you entered is incorrect! "];115Return116}117//If the password and account are correct, jump to the new interface118//Remove masks119 [Mbprogresshud Hidehud];120//Jump to new interface, use Segue (need to judge-manual)121 [Self performseguewithidentifier:@"LOGIN2CONTATC "sender:@"Top of the text "];122});123}124//This method is called before Segue jumps, and is passed into the Performseguewithidentifier method to create a good Segue object125-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender126 {127 NSLog (@"%@ ", sender);128 // forward transfer of data 129 //1. Get the target controller 130 Uiviewcontroller *vc= Segue.destinationviewcontroller; 131 //2. Set the title of the target controller 132 Vc.title=[nsstring stringwithformat:@ "%@ contact list", Self.numberField.text ]; 133 134 /*135// Implementation of the perform internal implementation of Segue 136 Uiviewcontroller *SOURCEVC = segue.sourceviewcontroller;137 Uinavigationcontroller *nav = sourcevc.navigationcontroller;138 [nav pushViewController:segue.destinationViewController animated:yes];139 */< Span class= "number" >140}141 @end         
Third, the use of Segue 1. Brief introduction

Each line on the storyboard for interface jumps is a Uistoryboardsegue object (abbreviated segue)

Three properties of 2.segue

Each of the Segue objects has 3 properties

Uniquely identifies the @property (nonatomic, readonly) NSString *identifier;

Source Controller @property (nonatomic, readonly) ID Sourceviewcontroller;

Target controller @property (nonatomic, readonly) ID Destinationviewcontroller;

Two types of 2.segue

According to Segue's execution (jump) moment, segue can be divided into 2 major types

Auto-type: After clicking on a control (such as a button), automatic execution of Segue, auto-complete interface jump

Control-Drag the line directly from the control to the target controller. When you click the "Sign in" button, it will automatically jump to the controller on the right. If you click on a control, do not need to make any judgment, be sure to jump to the next interface, it is recommended to use "Automatic type Segue"

Manual type: Need to write code to manually perform segue to complete the interface jump

Control-Drag the line from the source controller to the target controller. Manual type segue need to set an identity ().

At the right moment, use the Perform method to perform the corresponding Segue [self performseguewithidentifier:@ "login2contacts" sender:nil];

The segue must be executed by the source controller, which means that the perform method must be called by the source controller. If you click on a control, you need to make some judgments, that is to say: to meet certain conditions before jumping to the next interface, it is recommended to use "manual type Segue"

3. Performseguewithidentifier:sender:

Use Performseguewithidentifier: Method can execute a segue, complete interface jump

4.performseguewithidentifier:sender: The complete execution of a method

[Self Performseguewithidentifier: @ "login2contacts" sender:nil];

(1) According to identifier to find the corresponding line in the storyboard, new Uistoryboardsegue object

Set the Sourceviewcontroller of the Segue object (source Controller)

New and set Destinationviewcontroller (target controller) for the Segue object

(2) Call Sourceviewcontroller The following method, do some pre-jump preparation and pass in the creation of a good Segue object

-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) sender;

This sender was the sender of the Performseguewithidentifier:sender:

(3) Call the-(void) Perform of the Segue object; Method starts to perform interface jump operation

Get the Uinavigationcontroller where Sourceviewcontroller is located

Call Uinavigationcontroller's push method to press the Destinationviewcontroller into the stack to complete the jump

4. Transfer of data between multiple controllers

(1) Shun Pass: Transfer data from the current controller to the next controller

(2) Reverse transfer: Transfer data from the current controller to the front controller

iOS development UI Chapter-Implement a private Address Book small application (i)-Top of the text

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.