2013年9月4日 星期三
[詳細安裝圖文] Cocoapods 好用的第三方套件管理
官網是這麼形容的
The best way to manage library dependencies in Objective-C projects.
在Objective-c上管理Library最好的工具,
功能: 假如你在開發一個大型的專案, 裡面用了10幾套開源的第三方套件,
當這些套件更新的時候,以前的做法是Download下來,手動覆蓋掉舊的,
但假如是10幾個!太麻煩啦!!
何況你還要check是哪些有更新了.
cocoapods,看來是首選的solution.
安裝步驟
1. 打開 Terminal
2013年9月3日 星期二
超簡單- 無名搬家到Tumblr
Tumblr還算是個簡潔、好看的部落格,
介於重網誌(Blogger, wordpress) 與 一行文 (FB, tweeter)之間!
加上搬家非常簡單,大家可以趁著這個機會用看看喔!
1. 登入無名的帳號後,會看到
NSDate to NSString / NSString to NSDate
1. NSDate to NSString
//先建立你要的Format
NSDateFormatter*formatter =[[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss" ];
//看你的時區是什麼
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Taipei"]];
NSString*stringFromDate =[formatter stringFromDate:myNSDateInstance];
-----------------------------------------------------------------------------------------------------------------------------
2. NSString to NSDate
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Taipei"]];
NSDate *date = [dateFormatter dateFromString:@"2010-08-04 16:01:03"];
//先建立你要的Format
NSDateFormatter*formatter =[[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss" ];
//看你的時區是什麼
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Taipei"]];
NSString*stringFromDate =[formatter stringFromDate:myNSDateInstance];
-----------------------------------------------------------------------------------------------------------------------------
2. NSString to NSDate
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Taipei"]];
NSDate *date = [dateFormatter dateFromString:@"2010-08-04 16:01:03"];
2013年8月27日 星期二
用 NSNotification 註冊事件發生通知簡單3部曲
1. Add- 監聽事件的發生,一發生的話就執行Selector..
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didDismissSecondViewController)
name:@"ViewControllerDismissed"
object:nil];
2. Post- 事件發生時! 發出通知讓其他有加入此通知的地方去執行相對應的動作!
[[NSNotificationCenter defaultCenter] postNotificationName:@"SecondViewControllerDismissed"
object:nil
userInfo:nil];
3. Remove- 移除掉Observer,避免收到不必要的通知
暴力法: 寧可錯殺一百也不願放過一個 草菅人命
[[NSNotificationCenter defaultCenter] removeObserver:self];
明察秋毫法: 用name去找.. 關掉這部分的通知
[[NSNotificationCenter defaultCenter]
removeObserver:self name:@"SecondViewControllerDismissed" object:nil];
簡化精華三部曲,
可以用來傳遞參數或控制UI變化等等,上手後超級實用喔!
Xcode - No ARC support? 其他第三方的component不支援 ARC 怎辦
遇到某個檔案 No ARC Support? It's easy. " -fno-objc-arc" 就好!
選到你的Project
TARGETS-> 你的App -> Build Phases ->
找到那個不支援ARC的.m檔
完成!
UITableViewCell deselect 取消選取
有沒有遇到過UITableViewCell 按下去之後就一直有呈現選擇的狀態
只在didSelectRowAtIndexPath加上
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
// Your code here ...
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
animated YES的話會有藍色選取被漸淡的動畫
Singleton - 只要instance一次就可以當全域變數的方法
一般instance的方式:
myclass *instance = [[myclass alloc] init];
Singleton物件的方式:
myclass *instance = [myclass sharedInstance];
對於同一個物件,要在不同的view上面做共享時候
Singleton 是一個非常好用的方式
有點像是全域( global variable )變數一樣
在任何地方都可以共享他的value,
也透過這個方法作參數的傳遞.
標籤:
參數傳遞,
instance,
ios,
message passing,
objective c,
singleton,
xcode
訂閱:
文章 (Atom)



