0
我有一個開始太大的視圖控制器,所以我決定將所有的按鈕功能移動到一個單獨的擴展。在擴展中定義IBOutlet屬性
//MyViewController.h
@interface MyViewController : UIViewController
@end
//MyViewController+Buttons.h
@interface MyViewController (Buttons)
- (void)adjustButtons;
@end
//MyViewController+Buttons.m
@interface MyViewController()
{
}
@property (weak, nonatomic) IBOutlet UIButton *myButton;
@end
@implementation MyViewController(Buttons)
@end
界面生成器讓我的按鈕綁定到出口,但是當我跑我收到以下異常應用程序:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<MyViewController 0x12e501a70> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key myButton
我知道,它應該可以在一個擴展定義網點視圖控制器。我究竟做錯了什麼?
你也可以只把你的店鋪在類擴展.m文件內。這樣你就沒有頭文件中的所有東西,你的代碼看起來更乾淨。 – iFeli