01a- MenuButtons

  • 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開發範例大全第三章之四MenuButtons(4/7):2009年09月26日星期六

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

本文講第2個程式01a- MenuButtons,CookBook 中文譯本3-3~3-4、119~124頁(訣竅3-1):

(A) 這程式主要是做一個Navigation Bar,上面有兩個Button,左為Red button,右為Blue button,中間是Navigation menu的名字,click Red button顯示紅色,click Blue button顯示藍色。

 

(B) 本程式共有HelloController、SampleAppDelegate 兩個class及main(),HelloController內有goRed、GoBlue兩個action,一個init及loadView,loadView為重頭戲,設UIView、放Button、均在此,設menu 名字( (E)20行、self.title = ...)在init裡,SampleAppDelegate內產生一個NavigationController object。

(C)SampleAppDelegate內的55行為重點,產生一個UINavigationController object , UINavigationController inherite自UIViewController、UIResponder、NSObject,它不能subclass。initWithRootViewController將push最底層的root view。 54行的bounds回傳320x480整個螢幕(p61、若用applicationFrame則回傳去掉status bar後的320x460)。

我們看這nav,很妙的是,在56行,它可以nav.view,倒底這nav.view是那個view,其實就是HelloController class的view,由loadView來的。UInavigationController擴大了UIViewController,除了有UIViewController之外,又可以有NavigationBar、NavigationToolBar .... 等等,但nav仍有HelloController的UIViewController,所以,nav.view是合法的。

同時去看一下(D)loadView內,self.navigationItem、self.view都是可以的,因為UINavigationController inherit from UIViewController,UIViewController的view property(self.view)自然有。

(D)由SampleAppDelegate class的[windows addSubview:nav.view]中跳至loadView (因nav.view為nil),33~37行放上left button,40~44行放上right button。 注意27行,applicationFrame,表示這個UIView不含navigation bar(320x460, p61)。

(E)Action goRed及goBlue分別把application area填上紅色、藍色。

(F) 下圖來自Apple iPhone development center,定義了UINavigationController的畫面。由最下面的圖可知Navigation View包含整個畫面(status bar, navigation bar, custom content, navigation tollbar)。

如何做ToolBartoolBarItemsUIBarButtonClassUIBarButton Class reference? UINavigationItem Class reference? 即為UINavigationController最重要的項目。