<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                #### 加強版Hello World 實現步驟 1.創建HelloHaoMengZhu工程 在Xcode中創建HelloHaoMengZhu工程,?基于iPhone視圖基礎應用程序。 iPhone OS ->Application ->Single View?Application 2.修改HelloHaoMengZhuViewController.h 我們需要UITextField控件接受文字和響應一個按鈕點擊事件,? 所以在h文件中我們要定義一個UITextField屬性和一個響應事件方法。 3.修改HelloHaoMengZhuViewController.m #### 實現txtField屬性 實現-(IBAction)onClickButton:(id)sender方法 4.使用IB設計頁面,?擺放控件 打開Main.storyboard文件; 打開Library將控件拖入設計窗口?。 5.連接輸出口 為了將控件屬性通過屏幕“輸入”?或“輸出”?,我們需要定義“輸出口”?,? 在控制器中我們已經定義了與這個數據對應的屬性: @property?(?nonatomic,?retain)?IBOutlet UITextField *txtField; UITextField用于展示輸出和輸入數據。? 在iPhone(包括Mac)開發時候控件屬性要通過定義輸出口才能在屏幕中使用的。 在IB中,點擊鼠標右鍵,拖動New Referencing Outlet連線到File’s Owner。 設計區TextField控件并選擇屬性txtField。? 其中File’s?Owner代表控制器類。 ![](https://box.kancloud.cn/2016-01-06_568cf5c974476.jpg) 6.處理事件 為了響應控件的事件,?我們需要在控制器中定義一個事件處理方法: -(IBAction)onClickButton:(id)sender; 在iPhone(包括Mac)開發控件事件處理要自己編寫對應方法,? 并在IB中將控件的事件與該方法連接起來。 在IB中,?用鼠標右鍵拖到Button控件到File’s Owner,選擇發送事件。 其中File’s Owner代表控制器類。 ![](https://box.kancloud.cn/2016-01-06_568cf5c995d63.jpg) 7、編譯運行 點擊按鈕在輸入框里出現“Hello HaoMengZhu.” ![](https://box.kancloud.cn/2016-01-06_568cf5c9b8bea.jpg) #### MVC設計模式 MVC是一種設計模式,上面的例子就使用了MVC的設計模式。 所謂設計模式就是解決某一特定問題的方案。 MVC是解決具有UI的應用系統的成熟解決方案, 在Cocoa應用系統中嚴格按照該模式實現。 M-Model(模型)?是應用系統中與視圖對于部分的數據。 V -View(視圖)?是應用系統中用戶看到并與之交互的界面。 C-Controller(控制器)?是應用系統中起到控制器作用,接受用戶事件,顯示數據等等,與視圖進行交互等。 #### Cocoa MVC 采用 MVC 設計模式意味著,?Interface Builder 不需要編寫或生成任何代碼,? 您只需專注于應用程序的視圖。? Mac 的 Cocoa 綁定消除了大部分的黏合代碼,? 它就像連接在 Xcode 編寫的控制器和Interface Builder 設計的視圖之間的一條線,? 用圖形化的表示方法簡化了二者之間的關系。 Interface Builder 和 Cocoa 可以快速開發地您的應用程序。 ![](https://box.kancloud.cn/2016-01-06_568cf5c9e6368.jpg) ![](https://box.kancloud.cn/2016-01-06_568cf5ca08039.jpg)![](https://box.kancloud.cn/2016-01-06_568cf5ca2030f.jpg) #### 視圖控制器的方法 主要包括: ~~~ - (id)initWithNibName:(NSString *)nibNameOrNil bundle: (NSBundle *)nibBundleOrNil - (void)loadView - (void)viewDidLoad - (void)didReceiveMemoryWarning - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation - (void)viewDidUnload - (void)dealloc ~~~ 下面我們一一詳解: - (id)initWithNibName:(NSString *)nibNameOrNil?bundle:(NSBundle *)nibBundleOrNil 如果視圖使用NIB文件創建, 在加載視圖之前調用這個方法,?做一些初始化處理。 - (void)loadView 視圖加載時候調用的方法一般不使用NIB文件創建視圖時候使用,?而是通過代碼創建視圖對象。 - (void)viewDidLoad視圖加載之后調用方法,?我們常常在這個方法中做視圖初始化出來。 - (void)didReceiveMemoryWarning 當系統內存告警的時候,?調用的方法,?我們一般在該方法釋放一些耗費資源的對象。 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 用于處理屏幕旋轉的方法。 - (void)viewDidUnload 視圖對象卸載的時候調用的方法,一般在把內存視圖中屬性設置為nil的。 示例: ~~~ - (?void) viewDidUnload { self.?txtField?=?nil; } - (void)dealloc ~~~ 視圖對象內存釋放時候調用方法,?在該方法中先要釋放成員變量。 示例: ~~~ - (?void) dealloc { [txtField?release]; [super?dealloc]; } ~~~ #### 輸出口和動作 輸出口( Outlet)?,?為了實現控制器在視圖上輸入輸出結果,?需要定義輸出口?。 動作( Action)?,?為了實現視圖控制器響應視圖事件,?需要定義動作。 輸出口(Outlet)? 定義輸出口?,?是在ViewController定義一個控件屬性,? 如下: h文件: ~~~ @interface Hello_WorldViewController : UIViewController { UITextField *txtField; } @property (nonatomic, retain) IBOutlet UITextField *txtField; m文件: @synthesize txtField; ~~~ 動作(Action)? 定義動作,?是在ViewController定義一個方法,? 如下: h文件: ~~~ -(IBAction)onClickButton:(id)sender; m文件: -(IBAction)onClickButton:(id)sender { txtField.text = @"Hello World."; } ~~~ 動作( Action)?是在控件器中的方法,?但它的返回類型必須是IBAction聲明的,?該關鍵字告訴IB, 此方法是個Action,?可以被某個事件觸發。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看