[英]How to show activity indicator at the start of the app in iphone
我有一个应用程序,如果本地数据库中有数据,那么它将首先将其上传到服务器,然后再启动应用程序。我已在应用程序删除中编写了上传代码。我希望在上载时如何显示带有警报的活动指示器。 通常,很容易显示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;
}
显示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];
您可以根据需要自定义警报 。
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.