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

2015年1月26日 星期一

[iOS] 跳出警告 / 提醒訊息框

看到這個滿重要又實用的功能 ,決定寫起來記錄一下

在ViewController.m裡面增加 -(void)viewDidAppear:(BOOL) animated{}

簡單講就是宣告一個UIAlertController 然後建立風格、輸入訊息 以及增加按鈕

//
//  ViewController.m
//  Alert Dialog
//
//  Created by daniel on 2015/1/26.
//  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
{
    //產生一個UIAlertController 風格為 UIAlertcontrollerSyleAlert
    //風格可以換成UIAlertControllerSyleActionSheet
    UIAlertController *alertController = [UIAlertController
                                          alertControllerWithTitle:@"標題" message:@"訊息" preferredStyle:UIAlertControllerStyleAlert];
    
    //宣告一個確定按鈕
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault
    handler:^(UIAlertAction *action){
        //按下按鈕要做的事情寫在這
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
    //將確定按鈕加入到UIAlertController中
    [alertController addAction:okAction];
    //顯示這個Controller 也就是訊息框
    [self presentViewController:alertController animated:YES completion:nil];
}


@end


Action 那邊是類似onClick()的時候要做什麼這樣
Style可以選擇兩種



相信大家應該看程式碼就大概瞭解了吧?

就不多解釋了,不過在Objective-C裡面 nil = null這點可能要了解就可以了

END

2014年12月29日 星期一

[Android] No resource found that matches the given name '@style/Theme.AppCompat.Light' / 解決方法

剛開始安裝android / eclipse的時候通常都會遇到這個問題,

相信這個問題困擾許多人已久(包括我)...終於了解+找到解法以後把他寫起來以免下次又忘記!


首先,甚麼叫做IsLibrary?

這個選項打勾就代表說你把該專案當成library(所以不能亂勾,雖然勾了也沒太大影響(?))


Step1:
加入library(File->Import)



選擇sdk-extras-android-support-v7-appcompat資料夾,記得要勾選copy to workspace

Step2:

確認專案->右鍵Properties->anddroid(左側)->Library(isLibrary)是否勾選


Step3:

進到目標Project(就是有錯誤的那個project)

同樣也是properties->android->library->把錯誤的remove掉



add->剛剛新建立的android-support-v7-appcompat->OK (這邊請不要勾選is library)


Step4:

又發現錯誤!!



在builders這邊也有錯所以我們在Builders->Libraries->選擇錯誤的項目->edit->選圖片內的路徑

下面這個也有錯,所以也修正過來

Step5:

完成! 看到style.xml這邊完全沒有錯誤了,project也是沒有驚嘆號出現


就是這樣!幾個步驟做完就可以囉!

如果還是無法記得要去SDK Manager下載新的extras(要按install)

END