IOS項目-處女作,ios項目處女作

來源:互聯網
上載者:User

IOS項目-處女作,ios項目處女作

我最近一直都有在看關於IOS項目的知識,今天也總算是迎來了我的第一個IOS項目。不巧這個項目並不是從頭開始開發,而是在基礎上維護並添加一些模組。

噗~不管怎麼樣,還是來分析分析一下源碼吧~我這裡首先看到的是AppDelegate_iPad.m下的didFinishLaunchingWithOptions方法,這個方法顧名思義應該是應用啟動載入完成後所執行的一個方法。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    //[NSUserDefaults standardUserDefaults] 擷取使用者的一些配置資訊    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];    //initWithRootViewController的參數API是這樣說的,大概就是什麼controller都可以,但不能是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];    //不要顯示navigationcontroller的bar    [nav setNavigationBarHidden:YES];    //UIDevice可以擷取當前裝置資訊    if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0){        [self.window addSubview:nav.view];    }else{        self.window.rootViewController = nav;    }        [self.window makeKeyAndVisible];        return YES;}

 

接下來稍微的掃一下盲,NSUserDefualts standardUserDefualts是什麼呢?

NSUserDefaults standardUserDefaults用來記錄一下持續保留的資料非常方便,不需要讀寫檔案,而是保留到一個NSDictionary字典裡,由系統儲存到檔案裡,系統會儲存到該應用下的/Library/Preferences/gongcheng.plist檔案中。需要注意的是如果程式意外退出,NSUserDefaultsstandardUserDefaults資料不會被系統寫入到該檔案,不過可以使用[[NSUserDefaultsstandardUserDefaults] synchronize]命令直接同步處理到檔案裡,來避免資料的丟失。

接下來我們來看FFADSViewController~!往下走!GO!

#import "FFADSViewController.h"#import "FFLrcController.h"@implementation FFADSViewController-(void)viewWillAppear:(BOOL)animated{    [super viewWillAppear:YES];    [self.navigationController setNavigationBarHidden:YES animated:NO];}//這個頁就相當於app進入login頁面之前,需要緩衝一些資料會在這個頁面停留1-2秒種- (void)loadView {    [super loadView];    CGRect frame = CGRectMake(0, 0, 768, 1024);    UIImage * image = [UIImage imageNamed:@"ipadguodu"];    UIImageView * imageView = [[UIImageView alloc] initWithImage:image];    CGRect imageFrame = frame;    imageView.frame = imageFrame;    imageView.tag = 100;    //addSubview 添加子視圖    [self.view addSubview:imageView];    [imageView release];    //延遲2秒鐘後執行toController    [self performSelector:@selector(toController) withObject:nil afterDelay:2];}-(void)toController{    FFLrcController *publish = [[FFLrcController alloc]init];    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:publish];    //presentModalViewController:彈出視圖    [self presentModalViewController:nav animated:NO];    [publish release];}- (void)dealloc {    [super dealloc];}@end

 

 

這個controller很簡單,繼續往下走FFLrcController估計就是登入頁面了,真是不容易啊!走了好多路才到了登入介面。登入頁面首先執行的是loadView事件

註:remember、login、personnumber、password、state等屬性都已經在FFLrcController.h中定義

- (void)loadView {    [super loadView];//隱藏導航bar    [self.navigationController setNavigationBarHidden:YES animated:NO];    //設定背景顏色    self.view.backgroundColor=[UIColor colorWithRed:235/255.0 green:232/255.0 blue:222/255.0 alpha:1];     //label,設定相應的字型顏色背景等等資訊    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=@"記住登入狀態";    [self.view addSubview:remember];    [remember release];    //登陸    login = [[UITextField alloc] initWithFrame:CGRectMake(345, 452, 300, 40)];    login.backgroundColor = [UIColor clearColor];    login.borderStyle = UITextBorderStyleRoundedRect;    login.borderStyle=UITextBorderStyleNone;    //“委託的意思不就是自己的任務交給其他人去做麼”    //對象.delegate=self的意思就是對象的任務交給self去做  對象!=self    login.delegate = self;    login.keyboardType = UIKeyboardTypeDefault;    // use the default type input method (entire keyboard)    login.placeholder=@"姓名";    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=@"社會安全號碼碼";    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.returnKeyType = UIReturnKeyDone;    [self.view addSubview:password];//記住狀態    state = [UIButton buttonWithType:UIButtonTypeCustom];    state.frame =CGRectMake(50, 720, 52, 52);    //UIControlEventTouchDown事件後會轉跳到remember方法中做處理    [state addTarget:self action:@selector(remember) forControlEvents:UIControlEventTouchDown];    [state setBackgroundImage:[UIImage imageNamed:@"ipadcheckLogin"] forState:UIControlStateNormal];    [self.view addSubview:state];        //登陸按鈕    UIButton *check = [UIButton buttonWithType:UIButtonTypeCustom];    check.frame =CGRectMake(350, 725, 319, 72);    [check.titleLabel setFont:[UIFont boldSystemFontOfSize:18]];    //UIControlEventTouchDown事件後會執行goHome    [check addTarget:self action:@selector(goHome) forControlEvents:UIControlEventTouchDown];    [check setBackgroundImage:[UIImage imageNamed:@"ipadlogin_btn"] forState:UIControlStateNormal];    [self.view addSubview:check];    //他這裡condition方法編寫的是假如有記住密碼則將設定檔裡的資訊讀取到UITextField當中    [self condition];}

 

 

FFLrcController.h --->  goHome事件

- (void)goHome {    //交出第一響應的身份,可能是回收鍵盤操作    [login resignFirstResponder];    [personnumber resignFirstResponder];    [password resignFirstResponder];    //SVProgressHUD 是一個第三方的控制項,是一個彈出提示層,用來提示網路載入或提示對錯    [SVProgressHUD showWithStatus:@"資料載入中..." maskType:SVProgressHUDMaskTypeClear];    //不重複,只調用一次。timer運行一次就會自動停止運行    timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(loginTO) userInfo:nil repeats:NO]; }

 


FFLrcController.h --->  loginTO事件

-(void)loginTO{    //設定URL 這裡相當於 http://xxxx.com/CheckLogin/index/type/name/001/IDcardNO/331004xxxxxxxx/password/001/uuid/e1e2ed3sgfw2/macaddress/192.168.1.1/checkword/?p=ui
  //總之這個根據伺服器具體所需要的url來配置 NSString *urlString=[NSString stringWithFormat:@"%@/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]; //ASIHTTPRequest類庫中的ASIFormDataRequest是實現HTTP協議中的處理POST表單的很好的類庫。 ASIFormDataRequest *request = [[ASIFormDataRequest alloc] initWithURL:url]; [request setDelegate:self]; //成功後調用dataFetchComplete [request setDidFinishSelector:@selector(dataFetchComplete:)]; //失敗後調用dataFail [request setDidFailSelector:@selector(dataFail:)]; [request setTimeOutSeconds:60]; [[SEAOperationQueue mainQueue] addOperation:request]; [request release];}

 

 

FFLrcController.h --->  dataFetchComplete事件

- (void)dataFetchComplete:(ASIHTTPRequest *)request{    //隱藏進度條框    [SVProgressHUD dismiss];    //從伺服器中得到的資料是二進位的    NSData * data = [request responseData];    if (data) {
//從伺服器得到返回的資料轉UTF-8,這裡為什麼不是json,竟然帶有html的 NSString *myString = [[NSString alloc] initWithBytes:[data bytes] length:[data length] encoding:NSUTF8StringEncoding]; //這裡過濾掉一些標籤如:<script></script>等 //使用NSString的stringByReplacingOccurrencesOfString:@"要過濾的" withString:@"替換成的"方法 //以下省略9行過濾代碼
     if ([myString isEqualToString:@"您的社會安全號碼碼有誤!"]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"社會安全號碼碼輸入錯誤" delegate:nil cancelButtonTitle:@"確認" otherButtonTitles:nil, nil]; [alert show]; [alert release]; return; }else if ([myString isEqualToString:@"使用者名稱或密碼輸入錯誤!"]) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"登陸資訊輸入錯誤" delegate:nil cancelButtonTitle:@"確認" 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"]; } //記錄登陸時間寫入設定檔 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"YYYY-MM-dd"]; NSString *timestamp = [formatter stringFromDate:[NSDate date]]; NSString *countTime=@"上次登陸:"; countTime=[countTime stringByAppendingString:timestamp]; [[NSUserDefaults standardUserDefaults] setObject:countTime forKey:@"loginTime"]; [formatter release]; //這裡登陸成功後,寫入一些資訊到設定檔。這裡省去一些代碼 FFFFSwitchViewController *controller = [[FFFFSwitchViewController alloc]init]; controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; [self.navigationController pushViewController:controller animated:YES]; [controller release]; } }}

 

 

可以看到接下來就是FFFFSwitchViewController
----明天繼續寫

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.