Xib use, landing interface small test sledgehammer
Create a new view controller, see Click to view
Drag the desired control inside the created Vcroot.xib and drag it to the appropriate control to add the property and add the event to the login button.
Inside the VCRoot.h file:
#import <UIKit/UIKit.h> @interface vcroot : uiviewcontroller //iboutlet represents the Xib created from the@property(Weak,nonatomic)IboutletUitextfield *mname;@property(Weak,nonatomic)IboutletUitextfield *mpassword;@property(Weak,nonatomic)Iboutlet UIButton*mlogin;//Above @property are set properties//The following is a function event- (ibaction) Presslogin: (ID) sender;@end
Inside the vcroot.m file:
#import "VCRoot.h" @interface vcroot ()@end @implementation vcroot - (void) Viewdidload {[SuperViewdidload];additional setup after loading the view from its nib.}- (void) Didreceivememorywarning {[SuperDidreceivememorywarning];//Dispose of any resources, can be recreated.}/ * #pragma mark-navigation//in a storyboard-based application, you'll often want to do a little preparation before navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller using [Segue Destinationviewcontroller]. Pass the selected object to the new view Controller.} */- (ibaction) Presslogin: (ID) Sender {NSString* Name = @"Jack";NSString* Pass = @"123456";//Determine if correct, and popup dialog prompt if([_mname. TextIsequal:name] && [_mpassword. TextIsequal:pass]) {Uialertview * alert =[[uialertview alloc]initwithtitle:@"Hint"message:@"User name and password correct, login successful"DelegateNilcancelbuttontitle:@"OK"otherbuttontitles:@"Cancel",Nil]; [Alert show]; }Else{Uialertview * alert =[[uialertview alloc]initwithtitle:@"Hint"message:@"The user name and password are not correct, please re-enter"DelegateNilcancelbuttontitle:@"OK"otherbuttontitles:@"Cancel",Nil]; [Alert show]; }}//Click on the blank space to retract the keyboard-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (uievent *) event{[_mname Resignfirstresponder]; [_mpassword Resignfirstresponder];}@end
iOS development from beginner to proficient--xib use, landing interface small trial sledgehammer