IOS project-debut and ios project debut

Source: Internet
Author: User

IOS project-debut and ios project debut

I have been reading about IOS projects all the time recently. Today, I finally ushered in my first IOS project. Unfortunately, this project is not developed from the beginning, but is maintained and added with some modules.

Region ~ Anyway, let's analyze the source code ~ Here, I first see the didfinishlaunchingwitexceptions method under AppDelegate_iPad.m. As the name suggests, this method should be executed after the application is started and loaded.

-(BOOL) application :( UIApplication *) application metadata :( NSDictionary *) launchOptions {// [NSUserDefaults standardUserDefaults] obtain some user configuration information if ([[NSUserDefaults standardUserDefaults] stringForKey: @ "AddresstheText"] length] = 0) {[[NSUserDefaults standardUserDefaults] setObject: @ "http://xxxx.com" forKey: @ "AddresstheText"]; [[NSUserDefaults standardUserDefaults] synchronize];} [[NSUserDefaults standardUserDefaults] setObject: @ "wangmin" forKey: @ "userNameValue"]; [[NSUserDefaults standardUserDefaults] setObject: @ "1111" forKey: @ "useridValue"]; [[NSUserDefaults standardUserDefaults] synchronize]; FFADSViewController * controller = [[[FFADSViewController alloc] init] autorelease]; // The parameter API of initWithRootViewController is like this, probably any controller can be used, but it cannot be tabbarcontroller // The root view controller that is pushed on the stack with no animation. it cannot be an instance of tab bar controller. UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController: controller]; // do not display the bar of navigationcontroller [nav setNavigationBarHidden: YES]; // UIDevice can obtain the current device information if ([[UIDevice currentDevice]. systemVersion floatValue] <6.0) {[self. window addSubview: nav. view];} else {self. window. rootViewController = nav;} [self. window makeKeyAndVisible]; return YES ;}

 

Next, we will slightly scan the blind. What is NSUserDefualts standardUserDefualts?

NSUserDefaults standardUserDefaults is used to record permanently retained data, which is saved to an NSDictionary dictionary by the system instead of reading or writing files, the system will save the/Library/Preferences/gongcheng. plist file. Note that if the program unexpectedly exits, NSUserDefaultsstandardUserDefaults data will not be written to this file by the system, but you can use the [[NSUserDefaultsstandardUserDefaults] synchronize] command to directly synchronize the data to the file, to avoid data loss.

Next let's take a look at FFADSViewController ~! Go down! GO!

# Import "FFADSViewController. h "# import" FFLrcController. h "@ implementation FFADSViewController-(void) viewWillAppear :( BOOL) animated {[super viewWillAppear: YES]; [self. navigationController setNavigationBarHidden: YES animated: NO];} // This page is equivalent to the one-to-two (void) type of data that needs to be buffered before the app enters the login page) loadView {[super loadView]; CGRect frame = CGRectMake (0, 0,768,102 4); UIImage * image = [UIImage imageNamed: @ "ipadguodu"]; UIImageView * imageView = [[UIImageView alloc] initWithImage: image]; CGRect imageFrame = frame; imageView. frame = imageFrame; imageView. tag = 100; // addSubview add subview [self. view addSubview: imageView]; [imageView release]; // after a delay of 2 seconds, execute toController [self defined mselector: @ selector (toController) withObject: nil afterDelay: 2];} -(void) toController {FFLrcController * publish = [[FFLrcController alloc] init]; UINavigationController * nav = [[UINavigationController alloc] metadata: publish]; // presentModalViewController: pop-up view [self presentModalViewController: nav animated: NO]; [publish release];}-(void) dealloc {[super dealloc];} @ end

 

 

This controller is very simple. It is not easy to go down to the FFLrcController login page! The logon interface is only available after the logon process is completed. The loadView event is first executed on the logon page.

Note: attributes such as remember, login, personnumber, password, and state have been defined in FFLrcController. h.

-(Void) loadView {[super loadView]; // hide the navigation bar [self. navigationController setNavigationBarHidden: YES animated: NO]; // set the background color self. view. backgroundColor = [UIColor colorwithred: 235/255. 0 green: 232/255. 0 blue: 222/255. 0 alpha: 1]; // label, set the corresponding font color, background, and other information UILabel * remember = [[UILabel alloc] initWithFrame: CGRectMake (100,733,150, 30)]; remember. textColor = [UIColor colorWithRed: 189/255. 0 green: 183/255. 0 blue: 167 /255.0 alpha: 1]; remember. text = @ "Remember logon status"; [self. view addSubview: remember]; [remember release]; // log on to login = [[UITextField alloc] initWithFrame: CGRectMake (345,452,300, 40)]; login. backgroundColor = [UIColor clearColor]; login. borderStyle = UITextBorderStyleRoundedRect; login. borderStyle = UITextBorderStyleNone; // "do you mean to assign your tasks to others?" // object. delegate = self means that the task of the object is handed over to self for object creation! = Self login. delegate = self; login. keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard) login. placeholder = @ "name"; login. returnKeyType = UIReturnKeyDone; [self. view addSubview: login]; personnumber = [[UITextField alloc] initWithFrame: CGRectMake (345,545,300, 40)]; personnumber. backgroundColor = [UIColor clearColor]; personnumber. borderStyle = UITextBorderStyleRoundedRect; personnumber. borderStyle = UITextBorderStyleNone; personnumber. delegate = self; personnumber. keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard) personnumber. placeholder = @ "ID card number"; personnumber. returnKeyType = UIReturnKeyDone; [self. view addSubview: personnumber]; // password = [[UITextField alloc] initWithFrame: CGRectMake (345,636,300, 40)]; password. secureTextEntry = YES; password. backgroundColor = [UIColor clearColor]; password. borderStyle = UITextBorderStyleRoundedRect; password. delegate = self; password. borderStyle = UITextBorderStyleNone; password. keyboardType = UIKeyboardTypeDefault; // use the default type input method (entire keyboard) password. placeholder = @ "password"; password. returnKeyType = UIReturnKeyDone; [self. view addSubview: password]; // remember the state = [UIButton buttonWithType: UIButtonTypeCustom]; state. frame = CGRectMake (50,720, 52, 52); // After the UIControlEventTouchDown event is executed, it will jump to the remember method for processing. [state addTarget: self action: @ selector (remember) forControlEvents: UIControlEventTouchDown]; [state setBackgroundImage: [UIImage imageNamed: @ "ipadcheckLogin"] forState: UIControlStateNormal]; [self. view addSubview: state]; // the login button UIButton * check = [UIButton buttonWithType: UIButtonTypeCustom]; check. frame = CGRectMake (350,725,319, 72); [check. titleLabel setFont: [UIFont detail: 18]; // After the UIControlEventTouchDown event is executed, goHome [check addTarget: self action: @ selector (goHome) forControlEvents: UIControlEventTouchDown]; [check failed: [UIImage imageNamed: @ "ipadlogin_btn"] forState: UIControlStateNormal]; [self. view addSubview: check]; // here, the condition method is written to read the information in the configuration file to UITextField if you remember the password. [self condition];}

 

 

FFLrcController. h ---> goHome event

-(Void) goHome {// The identity for handing over the first response, which may be the function of revoking the keyboard operation [login resignFirstResponder]; [personnumber resignFirstResponder]; [password resignFirstResponder]; // SVProgressHUD is a third-party control, which is a pop-up prompt layer used to prompt for network loading or error [SVProgressHUD showWithStatus: @ "loading data... "maskType: SVProgressHUDMaskTypeClear]; // this parameter is not repeated and is called only once. Timer automatically stops running once it runs. timer = [NSTimer scheduledTimerWithTimeInterval: 0.1 target: self selector: @ selector (loginTO) userInfo: nil repeats: NO];}

 


FFLrcController. h ---> loginTO event

-(Void) loginTO {// set URL here is equivalent to http://xxxx.com/CheckLogin/index/type/name/001/IDcardNO/331004xxxxxxxx/password/001/uuid/e1e2ed3sgfw2/macaddress/192.168.1.1/checkword? P = ui
// In short, configure NSString * urlString = [NSString stringWithFormat according to the url required by the server: @ "% @/CheckLogin/index/type/name/% @/IDcardNO/% @/password/% @/uuid/% @/macaddress/% @/checkword /? P = ui"
, @ "Http://xxxx.com", login. text, personnumber. text, password. text, [self getUUID], [self getMacAddress]; // NSLog (@ "urlString % @", urlString); NSURL * url = [NSURL URLWithString: urlString]; // ASIFormDataRequest in the ASIHTTPRequest class library is a good class library for processing POST forms in HTTP. Required * request = [[ASIFormDataRequest alloc] initWithURL: url]; [request setDelegate: self]; // call dataFetchComplete after successful [request setDidFinishSelector: @ selector (dataFetchComplete :)]; // call dataFail [request setDidFailSelector: @ selector (dataFail :)]; [request setTimeOutSeconds: 60]; [[SEAOperationQueue mainQueue] addOperation: request]; [request release];}

 

 

FFLrcController. h ---> dataFetchComplete event

-(Void) dataFetchComplete :( ASIHTTPRequest *) request {// hide the progress bar [SVProgressHUD dismiss]; // The data obtained from the server is binary NSData * data = [request responseData]; if (data ){
// Get the returned data from the server to the UTF-8, why is it not json here, even with the html NSString * myString = [[NSString alloc] initWithBytes: [data bytes] length: [data length] encoding: NSUTF8StringEncoding]; // some labels such as <script> </script> are filtered out. // use stringByReplacingOccurrencesOfString of NSString: @ "the" withString: @ "replaced with" method to be filtered out // nine lines of filtering code are omitted below
If ([myString isEqualToString: @ "your ID card number is incorrect! "]) {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @" prompt "message: @" ID card number input error "delegate: nil cancelButtonTitle: @" OK "otherButtonTitles: nil, nil]; [alert show]; [alert release]; return;} else if ([myString isEqualToString: @ "incorrect user name or password! "]) {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @" prompt "message: @" logon information input error "delegate: nil cancelButtonTitle: @" OK "otherButtonTitles: nil, nil]; [alert show]; [alert release]; return;} else if ([myString hasPrefix: @ "/userid"]) {myString = [myString stringByReplacingOccurrencesOfString: @ "/userid/" withString: @ ""]; if (flag) {[[NSUserDefaults standardUserDefaults] setObject: @ "true" forKey :@" Flag "]; [self writeUser];} else {[[NSUserDefaults standardUserDefaults] setObject: @" false "forKey: @" flag "];} // record the logon time and write it to the configuration file NSDateFormatter * formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat: @ "YYYY-MM-dd"]; NSString * timestamp = [formatter stringFromDate: [NSDate date]; NSString * countTime = @ "Last login:"; countTime = [countTime stringByAppendingString: timestamp]; [NSUserDefaults stand ArdUserDefaults] setObject: countTime forKey: @ "loginTime"]; [formatter release]; // After logging in successfully, write some information to the configuration file. The following code is omitted: FFFFSwitchViewController * controller = [[FFFFSwitchViewController alloc] init]; controller. modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self. navigationController pushViewController: controller animated: YES]; [controller release] ;}}

 

 

The following figure shows FFFFSwitchViewController.
---- Continue writing tomorrow

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.