Created by Cao Shu on 16/2/25.
COPYRIGHT:EMOJI:2016 year Caohan. All rights reserved.
#import "ViewController.h"
@interface Viewcontroller ()
@property (Weak, nonatomic) Iboutlet Uitextfield *txtuser;
@property (Weak, nonatomic) Iboutlet Uitextfield *txtpwd;
@implementation Viewcontroller
Do no additional setup after loading the view, typically from a nib.
-(void) didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any of the can is recreated.
-(Ibaction) Loginclick: (ID) Sender {
Go to space before and after
NSString *username = [_txtuser.text stringbytrimmingcharactersinset:[nscharacterset WhitespaceCharacterSet]];
NSString *userpwd = [_txtpwd.text stringbytrimmingcharactersinset:[nscharacterset WhitespaceCharacterSet]];
Nsdictionary *jsondic = [self getjsondata:username userpwd:userpwd];
nsstring* Loginflag = [jsondic objectforkey:@ "Loginflag"];
NSLog (@ "%@", Loginflag);
[Self aletrinfo:loginflag];
-(Ibaction) Registbutton: (ID) Sender {
Uistoryboard *storboard = Self.storyboard;
Registviewcontroller *VC2 = [Storboard instantiateviewcontrollerwithidentifier:@ "VC2"];
[Self PRESENTVIEWCONTROLLER:VC2 animated:yes completion:nil];
Used to request PHP to get JSON
-(Nsdictionary *) Getjsondata: (NSString *) user_name userpwd: (NSString *) user_pwd {
NSString *urlstring = [NSString stringwithformat:@ "Http://192.168.1.106/iosLogin/index.php?action=login&user_ name=%@&user_pwd=%@ ", user_name,user_pwd];
Nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:urlstring]];
Put the requested URL data into the NSData object
NSData *response = [nsurlconnection sendsynchronousrequest:request returningresponse:nil Error:nil];
IOS5 the parsing class nsjsonserialization from the response to the data in the dictionary
Nsdictionary *jsondic = [nsjsonserialization jsonobjectwithdata:response options:nsjsonreadingmutableleaves Error: &error];
NSLog (@ "The data received is%@", jsondic);
-(void) Aletrinfo: (NSString *) loginflag{
Uialertview *alert = [[Uialertview alloc]init];
[Alert settitle:@ "hint"]; [Alert Setdelegate:nil];
[Alert addbuttonwithtitle:@ "OK"];
if ([Loginflag isequal: @ "0"]) {
[Alert setmessage:@ "Account or password error"];
if ([Loginflag isequal:@ "1"]) {
[Alert setmessage:@ "landed successfully"];