[英]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.