vouloir afficher UIProgressView sur UIAlertView

Salut les gars, je veux afficher UIProgressView sur UIAlertView pour afficher le traitement de téléchargement du file, mais j'ai trop cherché et find sur ce lien, mais encore incapable de le faire. Je ne comprends pas de cette

Si quelqu'un connaît la façon la plus simple de le faire, s'il vous plaît faites le moi savoir. Je serai reconnaissant.

Essayez ce code …

UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"" message:@"" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil]; UIProgressView *pv = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar]; pv.frame = CGRectMake(20, 20, 200, 15); pv.progress = 0.5; [av addSubview:pv]; [av show]; 

J'ai eu des problèmes à faire cela, et j'ai fini par ça:

 av = [[UIAlertView alloc] initWithTitle:@"Running" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]; progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar]; progressView.frame = CGRectMake(0, 0, 200, 15); progressView.bounds = CGRectMake(0, 0, 200, 15); progressView.backgroundColor = [UIColor blackColor]; [progressView setUserInteractionEnabled:NO]; [progressView setTrackTintColor:[UIColor blueColor]]; [progressView setProgressTintColor:[UIColor redColor]]; [av setValue:progressView forKey:@"accessoryView"]; [av show]; 

Bien que cela ne réponde pas tout à fait à votre question, essayez MBProgressHud , un contrôle tiers qui a cette fonctionnalité embeddede. Les exemples fournis sur Github devraient vous mettre au courant assez rapidement.

Essayez ce code. Mettez YES pour l'indicateur d'activité et NO pour progressView

 - (void) createProgressionAlertWithMessage:(NSSsortingng *)message withActivity:(BOOL)activity { progressAlert = [[UIAlertView alloc] initWithTitle: message message: @"Please wait..." delegate: self cancelButtonTitle: nil otherButtonTitles: nil]; // Create the progress bar and add it to the alert if (activity) { activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; activityView.frame = CGRectMake(139.0f-18.0f, 80.0f, 37.0f, 37.0f); [progressAlert addSubview:activityView]; [activityView startAnimating]; } else { progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(30.0f, 80.0f, 225.0f, 90.0f)]; [progressAlert addSubview:progressView]; [progressView setProgressViewStyle: UIProgressViewStyleBar]; } [progressAlert show]; [progressAlert release]; } 

Pourquoi ne pas utiliser la méthode alerviewdelegate

 - (void)willPresentAlertView:(UIAlertView *)alertView 

L'avantage de ceci est que nous pouvons voir quelle sera la taille de l'alertview à l'écran, comme iOS l'a précalculé à ce stade, donc pas besoin de nombres magiques – ou de surcharger la class contre laquelle Apple met en garde!

Et depuis iOS7, je me souviens d'avoir lu un document d'Apple disant de ne pas coder les tailles d'images mais de toujours les calculer à partir de l'application, ou quelque chose comme ça?

 - (void)willPresentAlertView:(UIAlertView *)alertView { CGRect alertRect = alertview.bounds; UIProgressView *loadingBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar]; loadingBar.bounds = CGRectMake(0, 0, alertRect.width, HEIGHT_YOU_WANT); // Do what ever you want here to set up the alertview, as you have all the details you need // Note the status Bar will always be there, haven't found a way of hiding it yet // Suggest adding an objective C reference to the original loading bar if you want to manipulate it further on don't forget to add #import <objc/runtime.h> objc_setAssociatedObject(alertView, &myKey, loadingBar, OBJC_ASSOCIATION_RETAIN); // Send the progressbar over to the alertview } 

Pour tirer reference à la barre de chargement dans

 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 

Ensuite, utilisez

 UIProgressView *loadingBar = objc_getAssociatedObject(alertView, &myKey); 

N'oubliez pas d'avoir défini

 #import <objc/runtime.h> static char myKey; 

En haut de votre déclaration de class

Ceci crée une vue d'alerte

UIAlertController * alert = [UIAlertController alertControllerWithTitle: @ Message "Message": @ "Ceci est un test" preferredStyle: UIAlertControllerStyleAlert];

maintenant append un champ de text

 [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { textField.placeholder=@"Enter Text label"; [textField setBorderStyle:UITextBorderStyleRoundedRect]; textField.backgroundColor=[UIColor whiteColor]; }]; 

et l'a ajouté sur la vue

[self presentViewController: alerte animée: OUI achèvement: néant];