
如果有心點,去尋找IBOutlet與IBAction的definition時,會發現…
#ifndef IBOutlet
#define IBOutlet
#endif
#ifndef IBAction
#define IBAction void
#endif
它是空的,其實它只是一個告訴Interface Builder的標籤。
IBOutlet是對應到視窗物件指標的識別標籤,它目的是讓Controller存取此物件。
舉個例子,可以再Controller中加入
IBOutlet UITextField *_TextField;
接下來就只要到Interface Builder中拉條線把關係建立起來,就可以靠_TextField來存取它
也就是說當我們想要顯示"Hello iPhone"在這個TextField時,就可以像這樣寫…
_TextField.text = @"Hello iPhone";
至於IBAction則是當某個動作被觸發時,用這個標籤告訴Interface Builder應該連結到的地方。
如果我們希望寫出一個當按鈕被按下時,就秀出Hello iPhone的小程式(就是Hello C++之類的作業)
我們就只要,打開XCODE,然後開始一個專案之後,在程式碼中加入這些東西
IBOutlet UITextField *_TextField; //point to an UITexField object on the view
- (IBAction)ButtomPressed{
_TextField.text = @"Hello iPhone";
}
接下來,就是打開IB開始大玩連連看
先把需要的元件放進去,

接下來就是大玩連連看

接下來 就是把上面的程式碼填入,就完成了第一個Hello iPhone小程式
