本文作者結合自身的實踐開發經驗,總結出了 22 個 iOS 開發的小技巧,以輕鬆的語調解決開發過程中所遇到的各種難題。
很簡單,添加 "self.tableView.tableFooterView = [[UIView alloc] init];",加完這句之後空白的 Cell 就不會再顯示了。

把 interactivePopGestureRecognizer 的 delegate 設為 self:
self.navigationController.interactivePopGestureRecognizer.delegate = (id<UIGestureRecognizerDelegate>)self;
self.automaticallyAdjustsScrollViewInsets = NO;
這個神器叫做 KMCGeigerCounter,快去 GitHub 上搬運吧,它能即時監測 FPS。

_myTableView.separatorInset = UIEdgeInsetsMake(0, 100, 0, 0);
重寫 touchesBegan 方法,在其中呼叫 [self.view endEditing:YES]; 即可。
使用基類,把背景設定寫在基類中讓所有子類繼承。
像拉 Button 一樣地拉你的約束,NSLayoutAttribute 也是可以拉線的。
navigationController.hidesBarsOnSwipe = YES
透過 setBackButtonTitlePositionAdjustment 把返回按鈕標題的偏移調到畫面外:
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
使用 MagicRecord。
使用 CSStickyHeaderFlowLayout。
可以透過判斷 pan 手勢的速度向量(velocityInView)來判斷方向,在 UIGestureRecognizerStateBegan 時計算 dx 與 dy 的絕對值大小,判定是水平還是垂直滑動,再依正負判斷上下左右,然後分別觸發對應的處理方法即可。
方法一:使用 resizableImageWithCapInsets(舊的 stretchableImageWithLeftCapWidth:topCapHeight: 已棄用)。方法二:如圖設定。

FlipBoard 出品的 FLAnimatedImage 太適合你了。
使用 SVPullToRefresh 庫,透過 addPullToRefreshWithActionHandler 並指定 position 即可。
_mTableView.tintColor = [UIColor redColor];

在 navigationController:willShowViewController:animated: 中重新設定 [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];。
把背景圖與 shadowImage 都設為空白的 [UIImage new],並將 translucent 設為 YES。
繼承 UITextField,重寫 drawPlaceholderInRect: 方法,在其中設定顏色並自行繪製 placeholder。
去 Stack Overflow 刷問題啊!這些看似瑣碎的技巧,背後都是無數開發經驗的累積,善用它們能讓日常開發事半功倍。