下面代码说明如何使用iPhone 非官方SDK在读取数据时显示进度条。

以下代码参考了MobileRss。

 

定义头文件:

  1. #import "uikit/UIProgressHUD.h"
  2.  
  3. @interface EyeCandy : UIApplication {
  4.  UIProgressHUD *progress;
  5. }
  6.  
  7. - (void) showProgressHUD:(NSString *)label withWindow:(UIWindow *)w withView:(UIView *)v withRect:(struct CGRect)rect;
  8. - (void) hideProgressHUD;
  9.  
  10. @end

上面的引号要改成<>。

  1. import "EyeCandy.h"
  2.  
  3. @implementation EyeCandy
  4. - (void)showProgressHUD:(NSString *)label withWindow:(UIWindow *)w withView:(UIView *)v withRect:(struct CGRect)rect
  5. {
  6.  progress = [[UIProgressHUD alloc] initWithWindow: w];
  7.  [progress setText: label];
  8.  [progress drawRect: rect];
  9.  [progress show: YES];
  10.  
  11.  [v addSubview:progress];
  12. }
  13.  
  14. - (void)hideProgressHUD
  15. {
  16.  [progress show: NO];
  17.  [progress removeFromSuperview];
  18. }
  19.  
  20. @end

使用下面代码调用:

  1. // Setup Eye Candy View
  2. _eyeCandy = [[[EyeCandy alloc] init] retain];
  3.  
  4. // Call loading display
  5. [_eyeCandy showProgressHUD:@"Loading …" withWindow:window withView:mainView withRect:CGRectMake(0.0f, 100.0f, 320.0f, 50.0f)];
  6.  
  7. // When finished for hiding the &quot;loading text&quot;
  8. [_eyeCandy hideProgressHUD];