View Controller理論背景

  • 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開發範例大全第三章之一View Controller理論背景(1/8):2009年09月08日星期二

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

本文講View Controller理論背景,文中材料及圖片均來自apple網站View Controller Programmin guide for iPhone OS

(A) 第三章要講View Controller,先看View Controller Programmin guide for iPhone OS,其中第一件重要的事 -- 什麼是View Controller?它究竟control什麼?

答:見下圖,Figure 1,這是iPhone螢幕,由上往下,有Status Bar、Navigation Bar、Application View、Tab Bar,另有Tool Bar(本圖中在Tab Bar下沒有顯示Tool Bar),View Controller的工作就是manage application view (在上、下Bar中間的那一塊)。application view中,程式設計師將data、control顯示在螢幕上,讓使用者操作,View Controller負責管理這個view及下一個view的顯示(the presentation of this views and the next view)。

(B)程式設計師如何將自己所要的畫面,以View Controllers呈現在iPhone上?

答:經由design pattern。程式設計師將自己所要的畫面,找適當iPhone所支援的design pattern,iPhone的View Controller support Model View Controllerl (MVC) design pattern,程式設計師找到MVC,並寫程式來完成它。除了你所寫的cunstom View Controllers,系統有三個特別view controllers,來管理Navigation Bar、Tab Bar、Table View,View Controllers整體觀念如下:

what are View Controller

User Interface design pattern

View controller clasess

using view controller

Tab Bar: 用來present multiple modes。

using tab bar controllers

Navigation Bar 上的Navigation controller:present views of hierarchical or sequential data。

using navigation controllers

另有modal view。

using modal view controllers

combining tab bar and navigation bar controllers

Table view controller:表現List of data。UIViewController

using table views for hierachical data

Autorotating views

 

(C)由(B)可知design pattern的重要性,再詳述 User Interface design patternView Controller的關係?

答:共分command interfaces、Radio interfaces、Navigation interface、Modal interface、Radio and navigation interfaces、Table interface六方面來看,如下:

command interfaces:用來執行不同的功能、工具,用tool bar (工具列) 。 這種user interface不用View Controller,用UIToolbar,見UIToolbar Class Reference

Radio interfaces:用來選不同modes。作法是tapping buttons on a Tab Bar。例如(見下圖 ):距是鐘錶,但有World Clock, Alarm, StopWatch, Timer四種modes呈現在下方Tab Bar。

Navigation interface:用來navigate a hierarchy of objects。Navigation Bar中有title、左有back button、右有Edit button(不一定有、optional)。見下圖。

Modal interface:modal interface覆蓋在application view之上的modal view,modal view會animate application view上所有東西、但不含status bar。如下圖。輕觸(tapping) Done button (下圖中最右的Save button),即可結束modal view。

Radio and navigation interfaces:很多程式會混合使用radio、navigation和modal interfaces。 如下圖。有favorite、Recents、Contacts三種不同的modes,tap Tab bar後Navigation Bar上出現該mode,然後可用Groups、+來操作。

Table interface: 見下圖。每行往右操作即為table view。