2012年8月18日 星期六

IBAction and IBOutlet

參考 http://xinnerliu.blogspot.tw/2010/07/ibaction-and-iboutlet.html

有两个与编写的代码‘通讯与绑定’的桥:
一个是IBOutlet :指界面元素在代码中的’代号‘
一个是IBAction:指界面元素产生事件在代码中的触发函数


IBAction (UI 動作輸入點 -入口) 是對應到Xcode上的UI(如UIButton)所需要動作的程式碼




example:
- (IBAction)enterPressed { //button 按下的動作
   
    [self.brain pushOperand:[self.display.text doubleValue]];
    self.userIsInTheMiddleOfTypingANumber = NO;
   
    self.description.text = [CalculatorBrain descriptionOfProgram:self.brain.program];


  
   ... show action
}




IBOutlet(UI 資料輸出點 -出口)是對應到視窗物件指標的識別標籤,它目的是讓Controller存取此物件。

example:
@property (weak, nonatomic) IBOutlet UILabel *display;

@property (weak, nonatomic) IBOutlet UILabel *expression;

@property (weak, nonatomic) IBOutlet UILabel *variables;