根據 MVC 模式,視圖(故事板)顯然應該連接到控制器層,也就是 ViewController。但在實作時卻發現無法正常關聯,如下圖所示:

這是改正之後的樣子。開始的時候連接的是 UIViewController,應該連接視圖控制器 ViewController 類。
類關係如下:
@interface ViewController : UIViewController @end
NS_CLASS_AVAILABLE_IOS(2_0) @interface UIViewController : UIResponder <NSCoding, UIAppearanceContainer, UITraitEnvironment, UIContentContainer>
NS_CLASS_AVAILABLE_IOS(2_0) @interface UIResponder : NSObject { @private }問題的根源就在於:故事板上的場景若仍指向系統原生的 UIViewController,就無法關聯到你自訂的 ViewController 裡的 IBOutlet 與 IBAction。只要把 Identity Inspector 中的 Custom Class 改成正確的 ViewController,拖線關聯就能恢復正常。改正之後,就可以順利連線了。