如何在iphone应用程序开始时显示活动指示器

如何在iphone应用程序开始时显示活动指示器,iphone,uiactivityindicatorview,Iphone,Uiactivityindicatorview,我有一个应用程序,如果本地数据库中有数据,那么它将首先将其上传到服务器,然后再启动应用程序。我已经在应用程序删除中编写了上传代码。我希望在上传过程中如何显示带有警报的活动指示灯。 通常很容易显示开始和停止,但在这种情况下如何操作 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self copy

我有一个应用程序,如果本地数据库中有数据,那么它将首先将其上传到服务器,然后再启动应用程序。我已经在应用程序删除中编写了上传代码。我希望在上传过程中如何显示带有警报的活动指示灯。 通常很容易显示开始和停止,但在这种情况下如何操作

   - (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;
      }

显示此操作的
UIActivityIndicator
需要将其放入appDelegatedidFinishLaunchingWithOptions。在不同的线程中执行上载,以便在执行操作时显示指示器。更改如下:

- (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;
      }
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];  
在警报中创建
UIActivityIndicator
并不困难。您可以按如下方式进行操作:

- (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;
      }
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];  
您可以根据需要自定义您的警报。

希望这能有所帮助。

这与“正常”有什么不同?(更好的是,这到底与Xcode有什么关系?你读过它的标签维基吗?@这个网站不是为了批评任何人,而是为了帮助我,如果我给了任何错误的标签,那么它就可以了,我会删除它。这一点不是批评——重点是人们应该学会正确使用这个网站。正如我所说的,Xcode标签不是针对一般的iOS相关问题,而是关于IDE本身。见鬼,我开发iOS应用已经两年了,但从来没有使用过Xcode。@H2CO3感谢我在你写的警告代码后提供的信息