使用 presentViewController:animated:completion: 呈現第二個 VC,點擊返回(dismissViewControllerAnimated:completion:)時,App 崩潰並輸出 Thread 1: Program received signal: "SIGABRT"。XIB 已正確連接 Outlet/Action。
原始碼中在 AppDelegate 已建立 self.secondView,但在第一個 VC 的跳轉邏輯中 又 new 了一個實例:
// 錯誤示範
SecondViewController *second = [[SecondViewController alloc] init]; // 新實例,非 AppDelegate 那個
[self presentViewController:second animated:YES completion:^{}];
導致:
init 而非 initWithNibName:bundle:)。self.secondView 從未被呈現,生命週期混亂觸發崩潰。修正:直接使用 AppDelegate 中已建立的實例,或統一用 Storyboard/XIB 載入:
// 正確做法 A:從 AppDelegate 取得
AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
[self presentViewController:app.secondView animated:YES completion:^{}];
// 正確做法 B:現代開發建議用 Storyboard + Segue,完全避免手動管理實例
檢查 SecondViewController.xib 在 File Inspector → Target Membership 是否勾選專案 Target。未勾選會導致 initWithNibName: 找不到 nib,回傳 nil,後續操作崩潰。
completion block 中捕獲 self 造成強循環,需用 __weak typeof(self) weakSelf = self;。secondView 在 AppDelegate 中是 strong 屬性,不會被過早釋放。objc_msgSend、-[UIViewController view] 等)。*** Terminating app due to uncaught exception 'NSInvalidArgumentException'... 具體訊息。原詢問者提到「書版本太舊、看部落格仍出錯」。強烈建議:

iOS View Controller 轉場崩潰 90% 源於「實例管理混亂」或「XIB 載入失敗」。採用 Storyboard + Segue 或統一工廠方法建立 VC,並善用官方 UICatalog 範例學習最佳實踐,能從根本上避免此類低級錯誤。