Я загружаю изображения из онлайн-изображения для кеширования в автономном режиме. Когда я открываю приложение, изображение было загружено полностью до появления UIAlertView. Неправильно закончено. Я хочу сделать всплывающий UIAlertView перед загрузкой изображений. Вот мой код ниже.
- (void) operatePopupUpdating {
myAlert = [[UIAlertView alloc] initWithTitle:@"Updating database.." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[myAlert show];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
indicator.center = CGPointMake(myAlert.bounds.size.width / 2, myAlert.bounds.size.height - 50);
[indicator startAnimating];
[myAlert addSubview:indicator];
[self operateUpdate];
[self updateImage];
[self operationCompleted];
}
В updateImage метод operationUpdate и operationCompleted
- (void)updateImage {
NSString *snake_ico_file = @"snake_img_icn_";
NSString *filePath = [self dataFile:[snake_ico_file stringByAppendingString:@"0.jpg"]];
int max_count = [[self readData] count];
if (![[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
for (int i = 0; i < max_count; i++) {
NSString *path = @"http://exitosus.no.de/drngoo/image/";
path = [path stringByAppendingFormat:@"%d",i];
NSString *ico_path = [path stringByAppendingFormat:@"/ico"];
//icon
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filename = [snake_ico_file stringByAppendingFormat:@"%d.jpg"];
NSString *localFilePath = [documentsDirectory stringByAppendingPathComponent:filename];
NSData *thedata = [NSData dataWithContentsOfURL:[NSURL URLWithString:ico_path]];;
[thedata writeToFile:localFilePath atomically:YES];
}
}
-(void) operationCompleted
{
[myAlert dismissWithClickedButtonIndex:0 animated:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Message form System" message:@"Database was updated successful" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
- (void)operateUpdate {
NSString *filePath = [self dataFileSettingPath];
int updatedVer = 0;
int version = [self checkDatabase];
if (version == -1) {
updatedVer = [self createDataBase:0];
} else {
updatedVer = [self updateDataBase:version];
}
[self.settingInfo setObject:[NSString stringWithFormat:@"%d",updatedVer] forKey:@"DBVersion"];
[self.settingInfo writeToFile:filePath atomically:YES];
}
Как я их исправляю и правильно работаю?