#pragma mark的用法

  • 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開發範例大全第五章之一:#prama mark:2009年09月18日星期五

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

看第一個程式---01a-Base Table,就遇上麻煩,見下圖一第3行及第16行,有#pragma mark ....,完全看不懂,上網查了,才知道,#pragma mark的用法, Mac Developer Tips講得很簡潔,現在解說如下:

(A) #pragma mark是Objective -C語言的一部份嗎?

答:不是。它純粹是Xcode的工具,對程式一點影響都沒有。若不想深入了解,直接跳過即可。

(B) #pragma mark的功用是什麼?

答:pragma這字在字典上查不到,近似字pragmatic的意義是活躍的、愛管閒事的、實用主義的。pragma mark實質上是讓Xcode在其Function Menu內打上一些記號,Function Menu就是圖一中兩個星號之下的那一塊,Function Menu列出程式檔內的class (左方有c字樣)、function(左方有f字樣)、method(左方有m字樣),這是Xcode讓使用者可以快速查看一個程式檔案裡所有class、method、function的工具,pragma mark則是在Function Menu內作記號(mark),幫助閱讀程式。

#pragma mark有兩種型式,

一是 #prama mark - (如圖一程式第3行)

在Function Menu會出現一條直線,如圖一的兩個星號之間,@interface HelloController之上的那一條細線。

當comment掉第3行後,Function Menu上的那一條細線就沒有了(見圖二)。

或是 #pragma mark UITableViewDataSource Methods (以 UITableViewDataSource Methods 為例 ) ((如圖一程式第16行)

在Function Menu內會出現#pragma mark後的所有字(並且以boldface呈現),如圖一的兩個+號之間的" UITableViewDataSource Methods "。

當comment掉第16行後,Function Menu上的UITableViewDataSource Methods就沒有了(見圖二)。

可以看一下圖二方塊圍住的Function Menu和圖一有何差異。是否用#pragma mark的圖一清楚很多,

  1. 有兩條直線分隔HelloController和SampleAppDelegate兩個class。
  2. 在HelloController class中,又分出init、 UITableViewDataSource MethodsUITableViewDelegate Methods

這就是#pragma mark的功能及用法 。

圖一:

圖二: