顯示具有 viewcontroller 標籤的文章。 顯示所有文章
顯示具有 viewcontroller 標籤的文章。 顯示所有文章

2015年1月27日 星期二

[iOS] 警告訊息框 + 帳號密碼輸入

練習到這部分又覺得這個功能很實用,於是又放上來了 。

其實跟昨天的那篇沒有差太多,但就是進階版本。(詳情可以看 警號訊息框 )

先放上完成圖 & code




一樣是在viewcontroller.m裡面做修改喔!

詳細的備註程式裡面有寫完整了,如果還不會也是可以發問

//
//  ViewController.m
//  AlertDialog_with_account_n_passwd
//
//  Created by daniel on 2015/1/27.
//  Copyright (c) 2015 daniel. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) viewDidAppear:(BOOL)animated
{
    //create a UIAlertController
    UIAlertController *alertController = [UIAlertController
                                          alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
    //declare a "cancel" button
    UIAlertAction *cacelAction = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleDefault handler: ^(UIAlertAction *action){
        [self dismissViewControllerAnimated:YES completion:nil];}];
    //declare a "login" button
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"login" style:UIAlertActionStyleDefault
        handler:^(UIAlertAction *action){
            NSString *uid = ((UITextField *) [alertController.textFields objectAtIndex:0]).text;
            NSString *pwd = ((UITextField *) [alertController.textFields objectAtIndex:1]).text;
            NSLog(@"account = %@",uid);
            NSLog(@"password = %@",pwd);}];
    //create first textfield
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)
    {textField.placeholder = @"Login";}];
    //create second textfield
    [alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)
    {textField.placeholder = @"password";
        textField.secureTextEntry = YES;}];
    
    [alertController addAction:cacelAction];
    [alertController addAction:okAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
                                  
}

@end


就是這樣囉!

END

2015年1月23日 星期五

[iOS] Apple XCode 6 初體驗

先把設備說一下:

Apple Mac Mini 2.4G這一款 1TB 8G RAM

系統是  : Yosemite 10.10

編譯程式: XCode 6


首先還是先創立一個Hello World 來熟悉一下介面


Main.storyboard 負責介面,介面上有任何問題就是看這個檔案


   接下來就是像android 一樣 你在xml檔上面建立的東西 要讓程式知道,所以按著control

   鍵拖曳到程式碼那邊就可以完成宣告了


   顯示出來就是長這樣


負責動作的部份是在  ViewController.m ( like onCreate, onPause)

負責宣告的部分則是在ViewController.h ( 介面--程式碼連結)


**這邊紀錄一下一開始在測試的時候模擬器都是黑屏,搞得很煩

最後解決方式是重新建立一個Project,不然一直有thread1:signal sigabrt 錯誤



大概就是這樣, Apple的開發跟Google差很多 習慣中End