03a- UpDownNavBar

  • warning: Declaration of views_handler_argument::init(&$view, &$options) should be compatible with views_handler::init(&$view, $options) in /home/xnvgu7/public_html/sites/all/modules/views/handlers/views_handler_argument.inc on line 745.
  • warning: Declaration of views_handler_filter::options_validate(&$form, &$form_state) should be compatible with views_handler::options_validate($form, &$form_state) in /home/xnvgu7/public_html/sites/all/modules/views/handlers/views_handler_filter.inc on line 585.
  • warning: Declaration of views_handler_filter::options_submit(&$form, &$form_state) should be compatible with views_handler::options_submit($form, &$form_state) in /home/xnvgu7/public_html/sites/all/modules/views/handlers/views_handler_filter.inc on line 585.
  • warning: Declaration of views_handler_filter_boolean_operator::value_validate(&$form, &$form_state) should be compatible with views_handler_filter::value_validate($form, &$form_state) in /home/xnvgu7/public_html/sites/all/modules/views/handlers/views_handler_filter_boolean_operator.inc on line 149.
  • warning: Declaration of views_plugin_style_default::options(&$options) should be compatible with views_object::options() in /home/xnvgu7/public_html/sites/all/modules/views/plugins/views_plugin_style_default.inc on line 25.
  • warning: Declaration of views_plugin_row::options_validate($form, &$form_state) should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/xnvgu7/public_html/sites/all/modules/views/plugins/views_plugin_row.inc on line 135.
  • warning: Declaration of views_plugin_row::options_submit($form, &$form_state) should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/xnvgu7/public_html/sites/all/modules/views/plugins/views_plugin_row.inc on line 135.

iPhone SDK開發範例大全第三章之六UpDownNavBar(6/7):2009年11月08日星期日

iPhone SDK開發範例大全即iPhone Developer's CookBook的中文譯本,程式可由erica網站下載。第三章講View Controller,程式共有七個。

本文講第3個程式03a- UpDownNavBar,CookBook 中文譯本3-5、125~126頁(訣竅3-2):

(A) 這程式主要是做一個Navigation Bar,上面有左右兩個Button,分別為Red、Blue,click button會顯示紅、藍色,中間有兩個上下箭頭image button,click Button會增加或減少數字,一開始,顯示50,按"下箭頭",數字成了49,按"上箭頭"兩次,數字成了51,如下圖。

 

(B)程式主體仍是loadView,其中:

  1. loadView是在HelloController class中,HelloController定義為:
    • @interface HelloController : UIViewController <UITabBarDelegate> {
      • int value;
    • }
    • @end
    • HelloViewController是inherit自UIViewController。並且conform to UITabBarDelegate。
  2. 36行~46定出applicationFrame是個UITextViewUITextViewinherit自 UIScrollView : UIView : UIResponder : NSObject,並alignmentCenter(18行)、用American Typewritter、size120的font(40行)。autoresizesSubviews(42行)、autoresizingMask是UIViewAutoresizingFlexibleWidth及UIViewAutoresizingFlexibleHeight(43行)。
  3. 48~53行,顯示數字50(50行),以及navigationBar的barStyle為UIBarStyleOpaque(53行)。
  4. 55~92行設定一個有上下箭頭image button的UIToolBar,UIToolBar inherit自UIView : UIResponder : NSObject
  5. 86~92行產生一個UIBarStyle(87行)為UIBarStyleBlackOpaque(OS3.0 deprecated)的UIToolBar,sizeToFit(89行)是UIView的Task,讓這個UIToolBar的size隨著其parentView(91行)--HelloViewController自動變動。
  6. 接著把一個個的 UIBarButtonItem產生出來(57~84行)、並放到UIBarStyle內 ,UIBarButtonItem inherit 自 UIBarItem:NSObject
  7. 91行將此toolbar以navigationItem(UIViewController class的property、navigationItem是pointer to UINavigationItem Class)放入(push)UINavigationBar ClasstitleView(UINavigationItem Class 的property )上。每個UINavigationItem 一定有一個左鍵(在左方---是back button)及一個title(在中間)。用setLeftBarButtonItemsetRightBarButtonItem改左右鍵,用titleView改中間的title。
  8. 95行用setLeftBarButtonItem( self.navigationItem.leftBarButtonItem )改左鍵為"Red",按下"Red"的action是goRed。
  9. 102行用setRightBarButtonItem( self.navigationItem.rightBarButtonItem )改右鍵為"Blue" 。按下"Blue"的action是goBlue。
  10. 至此,navigationBar完成了。

 

(C)在109~123行:有shouldAutorotateToInterfaceOrientation來處理iPhone轉向的問題,return YES(111行)表示自動轉畫面。114行increment:是76行的action,將畫面上的數字加一(116行)。119行decrement:是69行的action,將畫面上的數字減一(116行)。126行至135行是程式的入口class,由129行入口。

59~64行則是設定RootViewController(61行)。