這是一篇長期積累的零散筆記,涵蓋界面設置、時間處理、多線程、生命周期等日常會反復查閱的細節,適合當作速查表。
button.titleLabel.font = [UIFont systemFontOfSize:size];
NSDate *timeDate = [NSDate date]; NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init]; [dateformatter setDateFormat:@"yyyyMMddHHmmsssss"]; NSString *locationString = [dateformatter stringFromDate:timeDate];
- (BOOL)isBlankString:(NSString *)string {
if (string == nil || string == NULL) { return YES; }
if ([string isKindOfClass:[NSNull class]]) { return YES; }
if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
return YES;
}
return NO;
}
// 刷新整個表格 [_tableView reloadData]; // 只刷新當前行 [_tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
- (BMKAnnotationView *)mapView:(BMKMapView *)view viewForAnnotation:(id <BMKAnnotation>)annotation {
static NSString *AnnotationViewID = @"AnnotationViewID";
BMKAnnotationView *annotationView = [view dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
((BMKPinAnnotationView *)annotationView).pinColor = BMKPinAnnotationColorGreen;
annotationView.image = [UIImage imageNamed:@"XXX.png"];
return annotationView;
}
640*960、640*1136、750*1334、1242*2208
58*58、80*80、120*120、180*180
註冊入口:https://developer.apple.com/enroll/organization/ ,個人與組織賬號的資料要求不同,組織賬號需要鄧ományezés信息與資質材料。
[_myTimer invalidate]; _myTimer = nil;
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
NSJSONSerialization 返回什麼,取決於最外層結構:最外層是 {} 得到字典,是 [] 得到數組。取數據前先確認類型,避免崩潰。
修改 info.plist 中的「Supported interface orientations」,把 item 設為 Portrait 即可,這屬於全局設置。
搭框架 → 畫界面 → 寫功能 → 接接口 → 調試 → 做適配。初級側重 C 語言與 Objective-C/Swift 基礎,中級則要掌握項目開發、UI 體系與動畫圖層。
init → loadView → viewDidLoad → viewWillAppear → viewDidAppear → viewWillDisappear → viewDidDisappear → viewDidUnload → dealloc
1)主隊列通過 dispatch_get_main_queue 獲取,任務在主線程串行執行。
2)全局並發隊列通過 dispatch_get_global_queue 獲取,系統預置多個優先級,入隊順序與開始順序一致。
3)串行隊列用於順序化訪問共享資源,數量不限,不同串行隊列之間互為並發。
服務端返回的 JSON 解析後常夾帶 NSNull,直接當對象使用會引發崩潰。開源方案 NullSafe 用 Category 的方式統一接管了這類問題,集成進項目即可:
https://github.com/nicklockwood/NullSafe
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"provinces.plist" ofType:nil]; NSArray *arr = [NSArray arrayWithContentsOfFile:filePath]; // NSBundle 對應一個資源包,用來訪問包內文件並取得完整路徑 // 項目中添加的資源都會進主資源包 NSBundle *bundle = [NSBundle mainBundle]; NSString *file = [bundle pathForResource:@"shops" ofType:@"plist"]; shopsArray = [NSArray arrayWithContentsOfFile:file];
懶加載也稱延遲加載,寫法本質就是重寫 getter:第一次訪問時才實例化,之後直接返回已有對象,因此進入時必須先判空。它的好處有兩點:一是避免把大量創建代碼堆在 viewDidLoad 裡,可讀性更好;二是每個控件的初始化彼此獨立,耦合度低,維護時互不干擾。