Partage
  • Partager sur Facebook
  • Partager sur Twitter

utilisation d'UIActivityIndicatorView

    19 juillet 2011 à 12:19:13

    Bonjour à tous j'ai un probléme dont j'essaye de résoudre ça fait plus de deux jours
    En fait je veux afficher un UIActivityIndicatorView pendant le parsing d'un fichier xml pour affirmer l'utilisateur qu'il faut patienter.
    Voici le code que j'utilise
    - (void)viewDidLoad {
    	[self initSpinner];
    	[self LongApplication];
    	[super viewDidLoad];	
    	}  
    - (void)LongApplication {
    	
    	[NSThread detachNewThreadSelector: @selector(spinBegin) toTarget:self withObject:nil];
    	
    	sqlManager = [[SQLManager alloc] initDatabase];
    	//Vérification et création de la BDD
    	[sqlManager checkAndCreateDatabase];
    	tableau = [[NSMutableArray alloc] init];
    	url = [NSURL URLWithString: @"http://www.inov-tech.fr/YourFit/frenshFoodDB.xml"];
    	XMLToObjectParser *myParser = [[XMLToObjectParser alloc] parseXMLAtURL:url toObject:@"aliment" parseError:nil];
    	arrayCount = [[myParser items] count];
    	for(int i = 0; i<=arrayCount-1 ; i++) 
    	{
    		aliment *new = [[aliment alloc] init];
    		new = (aliment *)[[myParser items] objectAtIndex:i];
    		[tableau addObject:new];
    		NSLog(@"élément ajouté");
    	}  
    	
    		db=[sqlManager returnDataBase];
    		sqlite3_get_autocommit(db);
    		char** errmsg1=@"empty";
    		int result1 = sqlite3_exec(db, "BEGIN",nil,nil, &errmsg1);
    		
    		sqlite3_free(errmsg1);
    		NSLog(@"Début de la boucle de la boucle '%d'",[tableau count]);
    		for(int i = 0; i<[tableau count] ; i++) {
    			
    			aliment *new = [[aliment alloc] init];
    			new = (aliment *)[tableau objectAtIndex:i];
    			
    			[sqlManager insertIntoDatabase:new:db];
    			NSLog(@"C'est inséré");
    			
    			[new release];
    		}
    		NSLog(@"Sortie de la boucle");
    		char** errmsg;
    		int result = sqlite3_exec(db, "commit;",nil,nil, &errmsg);
    		
    		
    		sqlite3_free(errmsg);
    		sqlite3_close(db);
    	
    	[NSThread detachNewThreadSelector: @selector(spinEnd) toTarget:self withObject:nil];
    		
    }
    
    - (void)initSpinner {
    	UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc]      initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    	
    	indicator.center = CGPointMake(alert.bounds.size.width / 2, alert.bounds.size.height - 50);
    	
    	//[NSThread sleepForTimeInterval:1];
    	
    	alert = [[[UIAlertView alloc] initWithTitle:@"Parsing Elements\nPlease Wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
    	[alert show];	
    	[alert addSubview:indicator];
    
    }
    
    - (void)spinBegin {
    	 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    	[indicator startAnimating];
    	NSLog(@"indicateur commence");
    	[NSThread sleepForTimeInterval:1];
    	
    	
    	[pool release]; 
    }
    
    - (void)spinEnd {
    	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    
    	 [alert dismissWithClickedButtonIndex:0 animated:YES];
    	
    	[indicator stopAnimating];
    		[pool release]; 
    }
    

    Le pb est que l'UIActivityIndicatorView n'apparait qu'a la fin de l'éxécussion de la méthode LongApplication alors qu'il doit commencer avant que le mainthread l'éxécute et termine à sa fin.
    Je suis complétement bloquée :(
    Priére aidez moi
    Merci
    • Partager sur Facebook
    • Partager sur Twitter

    utilisation d'UIActivityIndicatorView

    × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
    × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
    • Editeur
    • Markdown