0

我有一个应用程序,如果本地数据库中有数据,那么它会在启动应用程序之前先将其上传到服务器我已经在应用程序 Deleage 中编写了上传代码我希望在上传时如何显示带有警报的活动指示器。通常很容易显示 startAnimating 和 Stop ,但是在这种情况下怎么办?

   - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    


     [self copyDatabaseIfNeeded];


     NSMutableArray *tempArray = [[NSMutableArray alloc] init];
     self.coffeeArray = tempArray;
     [tempArray release];

     [Coffee checkData:[self getDBPath]];


  int mytestcount=rowCount;
        NSLog(@"My Test ROw Count IS %d",mytestcount);


    if (mytestcount=0) {


    NSLog("No Data To Upload");

    }


   else {


    [Coffee getInitialDataToDisplay:[self getDBPath]];

    [self uploadData];
   }


   [self.window addSubview:[navigationController view]];

       [self.window makeKeyAndVisible];

       return YES;
      }
4

1 回答 1

0

显示UIActivityIndicator此操作需要将其放入appDelegate的didFinishLaunchingWithOptions中。在不同的线程中进行上传,只要进行操作,就会显示指标。变化如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

        [self copyDatabaseIfNeeded];
        NSMutableArray *tempArray = [[NSMutableArray alloc] init];
        self.coffeeArray = tempArray;
        [tempArray release];
        [Coffee checkData:[self getDBPath]];
        int mytestcount=rowCount;
        NSLog(@"My Test ROw Count IS %d",mytestcount);
        if (mytestcount=0) {
            NSLog("No Data To Upload");
        }
       else {
            [Coffee getInitialDataToDisplay:[self getDBPath]];
            //Set activity indicator here and perform uploading in different thread so that indicator is displayed as long as operation is carried out.  

           [self performSelector:@selector(uploadData) withObject:nil afterDelay:0];
       }
       [self.window addSubview:[navigationController view]];
       [self.window makeKeyAndVisible];
       return YES;
      }

UIActivityIndicator在警报中创建一个并不困难的任务。你可以这样做:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@" " message:@" " delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
UIActivityIndicatorView *progress= [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(125, 50, 30, 30)];
progress.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[alert addSubview:progress];
[progress startAnimating];   
[alert show];  

您可以根据需要自定义警报
希望这可以帮助。

于 2012-09-06T06:02:53.817 回答