成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Xcode 學習之路 Interface Builder使用技巧

移動開發 iOS
本文介紹的是Xcode 學習之路 Interface Builder使用技巧,在壇子里面逛,發現了這么一排呢好文章,與大家分享一下。

最近在看電驢上down下來的ipad開發視頻教程。為加深記憶,特在此做筆記。

前兩集視頻主要講的是UIAlertView(相當于windows里面的MessageBox)

在interface builder里面添加了控件之后,要想使得控件響應事件必須做如下處理:

1:在XXXViewController.h里面添加事件響應函數聲明如:

  1.   -(IBAction)btnOnclick:(id)sender; 

2:在相應的.m文件中實現這個函數

3:回到interface builder中鼠標右鍵從需要使用這個事件相應函數的控件拖拽到File's Owner上并在彈出的選項中選中步驟1中的函數名,使之關聯起來。

Xcode 學習之路 Interface Builder使用技巧

注意:這個視頻里面提到了一個特別的控件就是UIAlertView,因為這個控件沒有在interface builder中提供出來編輯。所以如果這個要使這個控件的事件得到相應需要在XXXViewController.h文件里面聲明類的時候使用協議(類似C++里面的抽象基類的多重繼承)。樣子如下:

  1. #import <UIKit/UIKit.h> 
  2. @interface AlertViewTestViewController : UIViewController <UIAlertViewDelegate>{  
  3. }  
  4. @end 

然后在實現文件里面實現對應的事件處理函數。對UIAlertView來說。要使用的協議是UIAlertViewDelegate,要實現的事件響應函數是 - (void)alertView:(UIAlertView* )alertView clickedButtonAtIndex:(NSInteger)buttonIndex。實際上,使用了協議之后,可以根據協議名字在幫助里面很快的找到這個協議需要實現哪些函數。

控件還有另外一個比較重要的東西就是數據綁定。在xcode里面要實現這么一個東西步驟基本和上面的類似

1:在XXXViewController.h文件里面聲明之,下面聲明了一個文本數據

  1. @interface OutletAndActionViewController : UIViewController {  
  2.     IBOutlet UITextField *txtName;  
  3. }  
  4. @property(nonatomic, retain) UITextField *txtName;  
  5. @end 

2:實現文件里面給出set和get函數。如果使用了屬性,你懂的。。。

  1. @synthesize txtName; 

3:回到interface builder中鼠標右鍵從File's Owner中拖拽到需要綁定這個數據的控件上并在彈出的選項中選中,使之關聯起來。拖拽方向和上面相反。寫到這里。我在想IBAction和IBOutlet到底是個啥?

Xcode 學習之路 Interface Builder使用技巧

在頭文件中找到了他們的定義:

  1. #ifndef IBOutlet   
  2. #define IBOutlet   
  3. #endif  
  4.  
  5. #ifndef IBAction   
  6. #define IBAction void   
  7. #endif 

幾乎啥都沒干。最后在cocoachina上找到了答案。

原帖:http://www.cocoachina.com/bbs/read.php?tid-18829.html

內容如下:

These two keywords do absolutely nothing as far as the compiler is concerned. IBOutlet gets entirely removed from the code before the compiler ever sees it. IBAction resolves to a void return type, which just means that action methods do not return a value. So, what’s going on here?
The answer is simple, really: IBOutlet and IBAction are not used by the compiler. They are used by Interface Builder. Interface Builder uses these keywords to parse out the outlets and actions available to it. Interface Builder can only see methods that are prefaced with IBAction and can only see variables or properties that are prefaced with IBOutlet. Also, the presence of these keywords tells other programmers, looking at your code in the future, that the variables and methods in question aren’t dealt with entirely in code. They’ll need to delve into the relevant nib file to see how things are hooked up and used.

敢情這兩關鍵字完全是給interface builder看的。

小結:Xcode 學習之路 Interface Builder使用技巧 的內容介紹完了希望本文對你有所幫助!

責任編輯:zhaolei 來源: 博客園
相關推薦

2011-08-03 14:13:45

Xcode 4 Interface

2011-07-20 09:49:41

Xcode Interface Builder

2011-07-28 13:47:20

Xcode Interface

2011-07-06 15:06:46

Xcode Cocoa

2011-08-05 10:01:23

Xcode Interface

2011-07-06 15:14:34

iOS Xcode

2011-08-11 16:31:08

XCode

2011-07-25 10:30:41

Objective-C Xcode 重構

2011-07-25 11:02:29

Objective-C Xcode 標簽

2011-07-25 10:14:13

Objective-C Xcode

2011-08-05 09:38:46

Interface B Cocoa 界面

2011-07-20 14:31:56

XCode User Scrip 腳本

2011-08-19 15:16:41

XCodeUserScripts腳本

2011-08-08 17:05:02

XCode UserScript 腳本

2011-08-05 09:48:46

iPhone Interface

2011-07-22 15:56:18

iPhone Interface Builder

2011-07-26 17:47:13

2013-04-18 10:19:40

iOS開發Xcode調試

2011-08-04 18:09:32

Xcode 技巧 文檔

2010-01-11 16:19:05

C++ Builder
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 午夜寂寞影院在线观看 | 亚洲激情一区二区三区 | 黄网免费看 | 成人激情视频在线播放 | 亚洲国产一区视频 | 欧美在线高清 | 久久综合九九 | 欧美日韩在线一区二区 | 日韩久久久久久 | 特黄色毛片 | 日韩美香港a一级毛片免费 国产综合av | 精品真实国产乱文在线 | 日韩视频一区在线观看 | 日韩精品二区 | 中文字幕亚洲免费 | 看羞羞视频免费 | 欧美日韩最新 | 亚洲午夜精品一区二区三区他趣 | 国产一区二区在线免费 | 男女羞羞在线观看 | 草久久久| 黄片毛片免费观看 | 日本中文字幕在线视频 | 神马久久久久久久久久 | 久久久久久免费免费 | 日韩成人精品一区二区三区 | 久久99蜜桃综合影院免费观看 | 亚洲自拍偷拍av | 久久久www| 亚洲97| 午夜影院在线观看免费 | 亚洲va在线va天堂va狼色在线 | 久久精品黄色 | 国产亚洲欧美日韩精品一区二区三区 | 国产成人免费视频网站高清观看视频 | 亚洲视频三 | 久久婷婷麻豆国产91天堂 | 国产成人高清成人av片在线看 | 成人免费看片网 | 国产精品一区一区 | 欧美亚洲国产日韩 |