6. New. User login model and login Interface Focus processing

Source: Internet
Author: User

Support gesture swipe back after using the self-brought push return 7.0.

1. Encapsulate a separate class to keep user logon information create a new class

Add Singleton.h header file definition properties in the. h file

  

  

And then to the. m file, define Single_implementation (Loginuser)

and import Nsstring+helper.h header files

and #define Kxmppusernamekey @ "Xmppusername"

#define Kxmpppasswordkey @ "Xmpppassword"

#define Kxmpphostnamekey @ "Xmpphostname"

Determine if isemptystring is empty string, only need to return (Self.length ==0);

-(NSString *) Loadstringfromdefaultswithkey: (NSString *) key

{

NSString *str = [[Nsuserdefaults standarduserdefaults] stringforkey:key];

return (str)? STR: @ "";

}

-(NSString *) userName

{return [self loadstringfromdefaultswithkey:kxmppusernamekey];}

-(void) Setusername: (NSString *) userName

{[UserName savetonsdefaultswithkey:kxmppusernamekey];}

-(NSString *) password

{return [self loadstringfromdefaultswithkey:kxmpppasswordkey];}

-(void) SetPassword: (NSString *) password

{[Password Savetonsdefaultswithkey:kxmpppasswordkey];}

-(NSString *) hostName

{return [self loadstringfromdefaultswithkey:kxmpphostnamekey];}

-(void) SetHostName: (NSString *) hostName

{[HostName savetonsdefaultswithkey:kxmpphostnamekey];}

This method of myjidname is defined in the. h file.

-(NSString *) myjidname

{return [NSString stringwithformat:@ "%@@%@", Self.username, Self.hostname];}

2. Import the newly created class in the login file.

Set the initial value of the interface text below the login and registration button

_usernametext.text = [[Loginuser sharedloginuser] userName];

_passwordtext.text = [[Loginuser sharedloginuser] password];

_hostnametext.text = [[Loginuser sharedloginuser] hostName];

Set Text Focus ... (The text box is empty automatically when the light box is anchored to the text box)

if ([_usernametext.text isemptystring]) {

[_usernametext Becomefirstresponder];

} else {

[_passwordtext Becomefirstresponder];

}

2. Write user logon information to System Preferences

[[Loginuser Sharedloginuser] setusername:username];

[[Loginuser Sharedloginuser] setpassword:password];

[[Loginuser Sharedloginuser] sethostname:hostname];

6. New. User login model and login Interface Focus processing

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.