呃...

其實不會有什麼精深的東西,也就只是把我學習過程記錄一下...

2014年7月27日 星期日

Some problems with my development Part.1 (tabBar, navigationItem, Segue)

since the article, I will use English to write my blog. If there are any problems in my blog, please tell me, thanks.

1. How to edit tabBar items in tabBarController?

[[self.tabBarController.tabBar.Items objectAtIndex:(Integer)] setTitle:(NSString)]

2. how to edit/define back/leftBarButton's title in navigationController?

[self.navigationController.navigationBar.topitem setTitle:NSString];(This is wrong!!)
There are three button types in navigationBar:
 a. leftBarButtonItem, you can define a custom leftBarButtonItem of navigationBar in the view controller where the button is.
 b. backBarButtonItem, you can define custom backBarButtonItem of navigationBar in the superview controller where the button is.
 c. default Button, if you don't define anything(left and back all nil), navigationController will auto-generate a back button.

setBackBarButtonItem method: Important! Assuming now have two view controllers which called A&B, and you want to change B's back Button. So setBackBarButtonItem must be wrote in A.
// backBarButtonItem doesn't need to put target and action, because it will work as function of back button.
    [[UIBarButtonItem alloc] initWithTitle:@"Customize backButton"
                                     style:UIBarButtonItemStyleBordered
                                    target:nil
                                    action:nil];
    [[self navigationItem] setBackBarButtonItem:newBackButton];
setLeftBarButtonItem method: Important! Writing these codes to customize button in view controller which you want to customize it.
// Don't forget to put target and action, or it doesn't work as button.
    [[UIBarButtonItem alloc] initWithTitle:@"Customize leftButton"
                                     style:UIBarButtonItemStyleBordered
                                    target:self
                                    action:@selector(-method)];
    [[self navigationItem] setLeftBarButtonItem:newBackButton];

P.S.: Left/back button instance variable is nil at begin in the navigationController, if want to change anything for left/back button, you must to create an UIButton object and assign to navigationController.

3. Performing segue after executing something what you want to do.

There are two steps:
    a. When you establish push relationship between view controllers, don't make it on button. Building it at any non-trigger component.
    b. Using the method which show as below to jump to next view after complete all what you want to execute.
    [self performSegueWithIdentifier:NSString sender:(id)]

2014年7月5日 星期六

chilkat blowfish for iOS data transmission PART3

這兩三個禮拜工作下來,發現其實沒什麼時間可以更新這邊的文章,上班拼命找solution,下班死命看knowledge,未來到勉強上手前,可能真的只會有筆記式的文章留在這了。
然後新人想去公司培養能力真的要慎選公司,公司沒有好的規劃也沒有專業領域前輩的話,進去只會非常非常非常的吃力,而且會浪費許多時間走彎路。
以上這意見僅供給想安穩過生活的人參考,在沒有不合理對待的前提下(像是薪資22k、責任制、要求幾天內要有成果),我認為做一件事最重要的是有沒有『興趣』,雖然我累得要命,但卻也累的快樂。『愛你所選』我認為是這麼解釋的:做你有興趣或有目的的事,並一直持續保持熱情地去做,而不是什麼把工作當成興趣,那只是無法朝向自己目標前進的人以及資方壓榨勞方的理由。人生短短幾十年,有必要把1/3或更多的時間花在自己其實並不感興趣的工作上嗎?三個傻瓜的道理,『追求卓越,成功自然隨之而來』,加油!

不廢話了,下面說明最後我實做的部分。

#import 
#import "CkoCrypt2.h"

@interface BlowFish : NSObject
-(NSString *) encode:(NSString *)str;
-(id) decode:(NSString *)str;
@end

先建立Blowfish的header file,並在前面繼上回的chilkat blowfish for iOS data transmission PART1, chilkat blowfish for iOS data transmission PART2已經設定好的CkoCrypt2的header file import進來(或@class),並建立encode與decode兩個實體方法(或要建類別方法也行)以及一個CkoCrypt2的物件供其它函數的使用。
#import "BlowFish.h"

@interface BlowFish()
@property CkoCrypt2 *crypt;
@end

@implementation BlowFish

-(instancetype)init{
    self = [super init];
    _crypt = [[CkoCrypt2 alloc] init];
    NSString *keyAscii = @"1234567812345678";
    NSString *ivAscii = @"12345678";
    if([_crypt UnlockComponent: @"Anything for 30-day trial"]){
        _crypt.CryptAlgorithm=@"blowfish2";
        _crypt.CipherMode = @"cbc";
        _crypt.EncodingMode = @"hex";
        _crypt.KeyLength = [NSNumber numberWithInt:256];
        _crypt.PaddingScheme = [NSNumber numberWithInt:3];
        [_crypt SetEncodedIV: ivAscii encoding: @"ascii"];
        [_crypt SetEncodedKey: keyAscii encoding: @"ascii"];
    }
    else
        NSLog(@"trail day is exceeded");
    return self;
}

-(NSString *) encode:(NSString *)str{
    return [_crypt EncryptStringENC:str];
}
-(id) decode:(NSString *)str{
    return [_crypt DecryptStringENC:str];
}
@end
implement裡面其實就沒什麼好說的,就是在init裡面把前面part1與part2說明過的一一設定完成即可,最後encode與decode方法return一個NSString的物件,那內容當然是encode或decode後的東西囉。
...
BlowFish *blowfh=[[BlowFish alloc] init];      //別忘了要init,在BlowFish中的所有設定都是放在init裡。
NSString *encodeStr=[blowfh encode:@"123"];    //123字串加密
NSLog(@"encodeStr:%@",encodeStr);              //可以看到16進位的一串數字
NSString *decodeStr=[blowfh decode:encodestr]; //123字串解密
NSLog(@"encodeStr:%@",decodeStr);              //可以看到123字串

呃,就像上面的註解囉。
以上,就是非常簡單但我浪費很多時間的chilkat的blowfish加密方式Orz