iPhone SDK開發範例大全第五章之二Base Table(1/10):

  • 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開發範例大全第五章之二Base Table(1/10):2010年05月29日星期六

iPhone SDK開發範例大全即iPhone Developer's CookBook的中文譯本,程式可由erica網站下載。第五章講基本表格,程式共有十個。看第一個程式---01a-Base Table。

本程式練習基本Table View,將系統裡的Font以Table View的方式表列,在iPhone simulator執行結果如圖一,程式列於圖二,原程式為OS2.0版,在OS3.0時,cell.text己無法使用了,故將第38行改為39行。程式解說如下:

本程式有三大部份,一為第5行、第8行的HelloController(是個UITableViewController),一為第76行、83行的SampleAppDelegate,一為第101行的main。第16行、第44行、第74行 #pragma的用法點此處

第101行的main:其作用只是程式的entry point。在104行,由SampleAppDelegate跳入主程式SampleAppDelegate(第83行)。

第76行、83行的SampleAppDelegate:其作用是有個applicationDidFinishLaunching為entry point,main一完就自動跳入此處。在其中產生一個window(第86行),產生一個是Navaigation的view(第87行 UINavigationView Controller),並將HelloController設為其Controller,由此跳入HelloController,在第88行將NavigationView Controller這個UIView加入wndow subview(此時成為HelloController view)。

第8行的HelloController:共分四部份,分別是第10行的init、第16行的UITableViewDataSource Methods、第44行的UITableViewDelegateMethods。

第10行的init:在SampleAppDelegate第87行[[HelloController alloc] init]時,init一個Hello contoller成為SampleAppDelegate的controller。

第16行的UITableViewDataSource Methods:table view需要Data Source,也就是顯示在table裡的資訊,需要有一個來源,UITableViewDataSource Methods就是提供資訊來源的一組methods。

  1. 第19行的numberOfSectionsInTableView:1(第21行)。
  2. 第25行的numberOfRowsInSection:有UIFont family這麼多伺Rows。[[UIFont familyNames] count] (第27行) 。
  3. 第31行cellForRowAtIndexPath:在第39行將[UIFont familyNames]放入cell。34~35行是找一塊memory給cell的標準用法。

第44行的UITableViewDelegateMethods:SampleAppDelegate結束,立刻執行的是HelloController裡的loadView(第59行),執行完,就開始執行第16行的UITableViewDataSource Methods,接著就進入loop等待,若有人點了某個cell就進入didSelectRowAtIndexPath(第47行)。

 

 

圖一:執行結果

 

 

圖二:程式