07a-ProgressBar1(10/15)

  • 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開發範例大全第四章之十07a-ProgressBar1(10/15):2009年11月12g日星期四

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

本文講第10個程式07a-ProgressBar1(10/15),CookBook 中文譯本4-9、154~157頁(訣竅4-7)。

(A)本程式在Naviagtion Bar上有"DO It" button,click這個button即出現一個UIActionSheet,並顯示一個progress bar,分20次,每0.5秒一次complete progress bar。

(B)達成pop up ActionSheet 的方法很簡單,下83行action:@selector(presentSheet)讓使用者click DoIt時跳至第40行的presentSheet。詳述presentSheet如下:

44行:UIActionSheet *basSheet = [UIActionSheet alloc ]產生UIActionSheet 物件。

45行~49行:

  1. 45行~initWithTitle : (NSString *) title讓title出現在receiver的title bar。receiver是一個UIActionSheet 物件。本例title是@"Please wiat "。
  2. 46行~delegate:(id) delegate,設立receiver的delegate。nil表示沒有,self表示receiver即為HelloController自己。
  3. 47行~cancelButtonTitle:(NSString *) cancelButtonTitle,cancel button的title,nil表示沒有cancel button。本message相當於addButtonWithTitle:。
  4. 48行~destructiveButtonTitle:(NSString *) destructiveButtonTitle,destructiveButton的title,nil表示沒有cancel button。本message相當於addButtonWithTitle:。
  5. 49行~otherButtonTitles:(NSString *)otherButtonTitles, ...,....表示可以有一串nil ended的(NSString *) ;本例是 nil。 本message相當於addButtonWithTitle:。
  6. return value:一個initialize好的UIActionSheet
  7. 50行設定5rows。
  8. 51行設定message為@"Updating internal Databases"。

53行開始設定UIProgressView,inherit自UIView:UIResponder:NSObject

53行產生一個寬220x長90的UIProgressView

54行設tag,25行會用到。

55行setProgressViewStyleUIProgressViewStyleDefault

60~61行設定setProgress為amountDone為0。progress property為.0~1.0之值,0.0表示開始,1.0表示完成。

62[NSTimer..] scheduleTimerWithTimeInterval 設定每次firing的interval為0.5秒,target是self (HelloController) , @selector是message incrementBar:(22行)。

22行~32行、 incrementBar:,詳如下。

24行,increment amountDone。

25行找到PROGRESSBAR progBar。

26行update progBar。

27~31行,當progress complete時,dismiss ActionSheet 、invalidate Timer等等。